: # NAME: # ksh.kshrc - global initialization for ksh # # DESCRIPTION: # Each invocation of /bin/ksh processes the file pointed # to by $ENV (usually $HOME/.kshrc). # This file is intended as a global .kshrc file for the # Korn shell. A user's $HOME/.kshrc file simply requires # the line: # . /etc/ksh.kshrc # at or near the start to pick up the defaults in this # file which can then be overridden as desired. # # SEE ALSO: # $HOME/.kshrc # # # AUTHOR: # Simon J. Gerraty # RCSid: # $Id: ksh.kshrc,v 1.1.1.1 2002/01/15 09:16:22 sjg Exp $ # # @(#)Copyright (c) 1991 Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. set +u # $_SOURCE_SH . source.sh _SOURCE_SH=: source() { f=$1; shift for d in `IFS=:; echo ${*:-$PATH}` do [ -s $d/$f ] || continue . $d/$f break done } case "$_INIT_" in "") # ooh, we bypassed /etc/profile? # are we in single user mode? if [ -d /usr/bin ]; then run_level=`(who -r) 2>/dev/null` case "$run_level" in *run-level*) run_level=`set -- $RUN_LEVEL; echo $3` case "$run_level" in S|5|0) _INIT_=single;; esac ;; esac unset run_level else # if /usr/bin is missing we had better be in single user _INIT_=single fi export _INIT_ ;; esac case "$-" in *i*) # we are interactive # Set PS1P=': ' in .profile if you want a prompt # that can be cut/pasted without harm. # The space after the : is necessary. #PS1P=${PS1P:-': '} if [ -w / ]; then PS1S="#${PS1P:+;}" else PS1S="${PS1P:+;}" PS1S="${PS1S:-\$}" fi case "$_INIT_" in single) ;; *) # we may have su'ed so reset these # NOTE: SCO-UNIX doesn't have whoami, # install whoami.sh USER=`( whoami )2>/dev/null` USER=${USER:-`id | sed 's/^[^(]*(\([^)]*\)).*/\1/'`} HOSTNAME=${HOSTNAME:-`uname -n`} # this yuk, is to work around failings of *BSD's # posix shell, which uses $ENV too, but can't handle # ksh'isms and does not ignore code bounded by # if [ "$RANDOM" != "$RANDOM" ] HOST=`IFS=.; set ${HOSTNAME:-unknown}; echo $1` # $TTY is the tty we logged in on, # $tty is that which we are in now (might be pty) # for Solaris and some others, basename won't do tty=`tty | sed 's,/dev/,,'` TTY=${TTY:-$tty} ;; esac set -o emacs # doesn't everyone prefer it? alias h='fc -l | more' _cd() { "cd" "$@"; } # Some posix /bin/sh will come here and die... if [ "x$RANDOM" != "x$RANDOM" ]; then if [ "$BASH" ]; then # bash is close enough that just about everything # should work - but no print builtin KSH_VERSION=BASH print() { case "$1" in -n) shift;; esac printf "$@" } else PS1S=":!$PS1S" fi # the PD ksh is not 100% compatible cdhist= case "$KSH_VERSION" in BASH) ;; *PD*) # PD ksh case "$KSH_VERSION" in *5.*) cdhist=ksh.cdhist esac case "$TERM" in pc3|xterm*|dtterm*) # bind arrow keys bind '^[['=prefix-2 bind '^XA'=up-history bind '^XB'=down-history bind '^XC'=forward-char bind '^XD'=backward-char ;; esac ;; *) # real ksh ? cdhist=ksh.cdhist set -o trackall case "$TERM" in vt*|xterm*|dtterm*) # Kevin Gallagher in comp.emacs! alias __A= # up arrow alias __B= # down arrow alias __C= # right arrow alias __D= # left arrow ;; esac ;; esac if [ "$cdhist" ]; then source $cdhist $HOME/etc $ETC /etc fi # If REAL_TERM is defined, we are likely in screen(1) # see w__screen() below. Of course we lose if we # re-attach to a different terminal type! case "${REAL_TERM:-$TERM}" in sun*) if [ "$tty" != console ]; then # ilabel ILS='\033]L'; ILE='\033\\' # window title bar WLS='\033]l'; WLE='\033\\' fi ;; xterm*|dtterm*) ILS='\033]1;'; ILE='\007' WLS='\033]2;'; WLE='\007' ;; hpterm*) # slightly different model, # so define the functions ourselves. ils=label ilabel() { _a="$@"; print -n "\033&f-1k${#_a}D${_a}"; } label() { _a="$@"; print -n "\033&f0k${#_a}D${_a}"; } ;; *) ;; esac case "$TERM" in screen) if [ "$ILS" ]; then # augment the ILS etc with necessary # escapes so that screen will pass them # to the real terminal. ILS="\033P${ILS}screen:" WLS="\033P${WLS}screen:$WINDOW " case "$ILE" in *\033\\*) ;; *) ILE="$ILE\033\\" WLE="$WLE\033\\" ;; esac fi ;; esac # do we want window decorations? if [ "$ILS" ]; then PUSER=${PUSER:-$USER} if [ "$ils" != label ]; then ilabel () { print -n "${ILS}$*${ILE}"; } label () { print -n "${WLS}$*${WLE}"; } fi alias stripe='label "$USER@$HOST ($tty) $TTY_TAG - $PWD"' alias istripe='ilabel "$USER@$HOST ($tty) $TTY_TAG"' # make sure title bar is updated w_cd() { _cd "$@"; eval stripe; } alias cd=w_cd w_label() { label "$@"; ilabel "$@"; } # these are commands that take us elsewhere... # so istripe too. for c in ${W_CMDS:-su sudo rlogin telnet kermit stelnet ftp tip ssh} $XTRAW_CMDS do eval "w_$c() { w_label \"$c \$@\"; \"$c\" \"\$@\"; eval istripe; eval stripe; }" eval alias $c=w_$c done # screen needs a bit more help w__screen() { REAL_TERM=${REAL_TERM:-$TERM} export REAL_TERM w_label "screen@$HOST" "screen" "$@" eval istripe eval stripe } alias screen=w__screen eval stripe eval istripe fi fi alias quit=exit alias cls=clear alias logout=exit alias bye=exit alias p='ps -l' alias j=jobs alias o='fg %-' alias ls='ls -gCF' # add your favourite aliases here alias rsize='eval `"resize"`' alias resize=rsize case "$_INIT_" in single) PROMPT="$PS1P\${PWD##*?/}$PS1S " ;; *) # if you always want user@host in prompt # set and export PUSER in .profile PUSER=${PUSER:-$USER@$HOST} PROMPT="$PS1P$PUSER$PS1S " PPROMPT="$PS1P$PUSER:\${PWD##*?/}$PS1S " OS=${OS:-`uname`} OSREL=${OSREL:-`uname -r`} case $OS in HP-UX) alias ls='ls -CF' ;; *BSD) alias df='df -k' alias du='du -k' ;; SunOS) case $OSREL in 5*) alias ls='ls -CF' alias df='df -k' alias rsize='eval `"resize"`; stty rows $LINES' ;; esac ;; esac case "$TERM" in sun*|xterm*|dtterm*) case $tty in pts/*|tty[p-w]*) case "$DISPLAY" in "") DISPLAY=`who | grep "$TTY " | sed -n 's/.*(\([^:)]*\)[:)].*/\1/p'`:0 ;; esac ;; esac export DISPLAY ;; esac ;; esac PS1="$PROMPT" case "$PS1" in :*) PS2=" ";; esac ;; *) # non-interactive ;; esac # commands for both interactive and non-interactive shells source add_path.sh $HOME/etc $ETC /etc source ksh.site $HOME/etc $ETC /etc