# ============================================================================ # Environment File for ksh # Literatur : [1] The Kornshell Morris I.Bolski / David G.Korn # Martin Zahn 30.9.91 # ============================================================================ # # Define Aliases # alias fn="typeset +f" # Show all build in ksh Function Names alias fun="typeset -f" # Show all build in ksh Function Definitions alias h="fc -l" # Show history file alias kk="ls -la | more" alias ll="ls -la" # Settings for JOB-CONTROL stty tostop # Background Jobs stops when using stdin, stdout stderr stty susp  # Suspend Foreground Jobs with CTRL Z # Reduce the time that it takes ksh to do a pathname search # for a command. ksh defines a tracked alias for a command name # when the command is first encountered. (see alias -t) set -o trackall # Do not store function definitions in the history file # (Not supportet in this release of ksh) set -o nolog # Allow to overwrite files with I/O Redirection ">" unset noclobber # No Pathname expansion for better performance # set -o noglob # # Enhanced cd Interface: # Redfine build in Command ([1] Page 71) # unalias cd alias cd=_cd # # Enhanced cd Interface: # Global Variables in Korn Shell should have an underscore to be # different from any other variables # integer _stack_max_index=${CDSTACK-32} # _push_max_index : max Index in the Directory-Stack Array integer _stack_index=_stack_max_index # _stack_index : current Index in the Directory-Stack Array _directory_stack[_stack_index]=\~ # _directory_stack[] : this is the Directory-Stack Array _host=`uname -n` # _host : Host-Name of this system # ------------------------------------------------ # Display current directory and directories in the # directory-stack in one column. # ------------------------------------------------ function sd { # Display all items in the Directory-Stack preceded by a number # with the select statement. select prints the PS3 prompt at # the end of the list, so redefine PS3 to nothing PS3= select i in "${_directory_stack[@]}" do : # Do nothing with the items, just show them done < /dev/null } # ------------------------------------------------ # Manipulate Directory-Stack # ------------------------------------------------ function _cd { # # Local Variables, known only within this function # integer MAXPROMPTLEN=0 # Max Length of prompt calulated from COLUMNS typeset dir= # Current Directory integer n=0 # Index for Directory Stack Array typeset integer type=4 # Defines the kind of cd # type=1 : cd - : cd back to the previous Directory # type=2 : cd i : cd to Directory shown with sd # type=3 : Move Directories in Stack one Step down # type=4 : cd directory : Fill the Directory-Stack # # Set $1 to $HOME if cd has no arguments # set ${1:-$HOME} # # Set "type" and "n" depending what kind of cd user typed # "n" is just a dummy variable for the Directory-Stack Index # case $1 in # check first argument of cd -|-1) # cd - : cd back to the previous directory n=_stack_index+1 type=1 ;; [1-9]|[1-9][0-9]) # cd i : cd to the Directory shown with sd n=_stack_index+${1}-1 type=2 ;; *) # check if Directory-Stack is full if ((_stack_index <= 0)) then type=3 n=_stack_max_index fi ;; esac # # Check the range of the Directory-Stack when user choose cd i # if ((type < 3)) then if ((n > _stack_max_index)) then print - "cd: Directory stack not that deep, out of range problem" return 1 else dir=${_directory_stack[n]} # Read the Directory-Stack for cd i fi fi # # Replace "~" with $HOME if dir is "~/subdir" # This is necessary for cd - if the last directory # is "~/subdir" in the Directory-Stack # case $dir in ~*) dir=$HOME${dir#~} ;; esac # # cd to $dir if set, else to argument of cd # return if cd is not possible # \cd "${dir:-$@}" > /dev/null || return 1 # # Replace HOME with "~" for Prompt PS1 # # Extract HOME/ from HOME/subdir/subdir --> subdir/subdir # PWD does not include HOME/ : dir=PWD # PWD does include HOME/ : Cut including Part of HOME/ from PWD and set dir=Rest of HOME # # dir=${PWD#$HOME/} case $dir in $HOME) dir=\~ ;; /*) ;; *) dir=\~/$dir ;; esac # # Manipulate Directory-Stack # case $type in 1) # cd - : swap first two elements typeset temp=${_directory_stack[_stack_index]} _directory_stack[_stack_index]=$dir _directory_stack[n]=$temp ;; 2|3) # Directory-Stack is full or cd i, so # put $dir on top and shift down by one all other Directories # The least recently referenced directory is removed from the list integer i=_stack_index for x in "$dir" "${_directory_stack[@]}" do ((i > _stack_max_index)) && break _directory_stack[i]=$x i=i+1 done ;; 4) # cd argument : Fill Directory-Stack until _stack_index is 0 # This case is only true when Directory-Stack is not jet full # this happens when you login in and start working _stack_index=_stack_index-1 _directory_stack[_stack_index]=$dir ;; esac # # Show Prompt # COLUMNS=${COLUMNS:-80} MAXPROMPTLEN=COLUMNS/5 if ((${#dir} > $MAXPROMPTLEN)) then dir=$(print $dir | awk ' { print substr($0, length($0)-"'$MAXPROMPTLEN'", length($0)) } ') dir="...$dir" fi # PS1="$_host:$LOGNAME:$dir> " PS1="`tput smso`$LOGNAME:$dir>`tput rmso` " export PS1 } function uncd { unalias cd PS1="$_host:$LOGNAME:> " } # # export functions # typeset -xf _cd typeset -xf sd # # debug function with option typeset -ft # # typeset -ft _cd # typeset -ft sd