[BACK]Return to ksh.kshrc CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/ksh.kshrc, Revision 1.29

1.1       downsj      1: :
1.29    ! tb          2: #      $OpenBSD: ksh.kshrc,v 1.28 2017/07/15 07:11:42 tb Exp $
1.1       downsj      3: #
                      4: # NAME:
1.8       deraadt     5: #      ksh.kshrc - global initialization for ksh
1.1       downsj      6: #
                      7: # DESCRIPTION:
                      8: #      Each invocation of /bin/ksh processes the file pointed
                      9: #      to by $ENV (usually $HOME/.kshrc).
                     10: #      This file is intended as a global .kshrc file for the
                     11: #      Korn shell.  A user's $HOME/.kshrc file simply requires
                     12: #      the line:
                     13: #              . /etc/ksh.kshrc
                     14: #      at or near the start to pick up the defaults in this
                     15: #      file which can then be overridden as desired.
                     16: #
                     17: # SEE ALSO:
                     18: #      $HOME/.kshrc
                     19: #
                     20:
                     21: # RCSid:
                     22: #      $From: ksh.kshrc,v 1.4 1992/12/05 13:14:48 sjg Exp $
                     23: #
                     24: #      @(#)Copyright (c) 1991 Simon J. Gerraty
                     25: #
                     26: #      This file is provided in the hope that it will
                     27: #      be of use.  There is absolutely NO WARRANTY.
                     28: #      Permission to copy, redistribute or otherwise
1.8       deraadt    29: #      use this file is hereby granted provided that
1.1       downsj     30: #      the above copyright notice and this notice are
1.8       deraadt    31: #      left intact.
1.1       downsj     32:
                     33: case "$-" in
                     34: *i*)   # we are interactive
                     35:        # we may have su'ed so reset these
1.25      rpe        36:        USER=$(id -un)
                     37:        UID=$(id -u)
1.1       downsj     38:        case $UID in
                     39:        0) PS1S='# ';;
                     40:        esac
1.12      david      41:        PS1S=${PS1S:-'$ '}
1.28      tb         42:        HOSTNAME=${HOSTNAME:-$(uname -n)}
1.1       downsj     43:        HOST=${HOSTNAME%%.*}
                     44:
                     45:        PROMPT="$USER:!$PS1S"
                     46:        #PROMPT="<$USER@$HOST:!>$PS1S"
                     47:        PPROMPT='$USER:$PWD:!'"$PS1S"
                     48:        #PPROMPT='<$USER@$HOST:$PWD:!>'"$PS1S"
                     49:        PS1=$PPROMPT
                     50:        # $TTY is the tty we logged in on,
                     51:        # $tty is that which we are in now (might by pty)
1.28      tb         52:        tty=$(tty)
                     53:        tty=${tty##*/}
1.12      david      54:        TTY=${TTY:-$tty}
1.21      rpe        55:        # $console is the system console device
1.26      rpe        56:        console=$(sysctl kern.consdev)
1.21      rpe        57:        console=${console#*=}
1.8       deraadt    58:
1.1       downsj     59:        set -o emacs
                     60:
                     61:        alias ls='ls -CF'
                     62:        alias h='fc -l | more'
1.20      rpe        63:
1.1       downsj     64:        case "$TERM" in
1.3       marc       65:        sun*-s)
                     66:                # sun console with status line
1.22      rpe        67:                if [[ $tty != $console ]]; then
1.1       downsj     68:                        # ilabel
                     69:                        ILS='\033]L'; ILE='\033\\'
                     70:                        # window title bar
                     71:                        WLS='\033]l'; WLE='\033\\'
                     72:                fi
                     73:                ;;
                     74:        xterm*)
                     75:                ILS='\033]1;'; ILE='\007'
                     76:                WLS='\033]2;'; WLE='\007'
1.29    ! tb         77:                pgrep -qxs $PPID telnet && export TERM=xterms
1.1       downsj     78:                ;;
                     79:        *)      ;;
                     80:        esac
                     81:        # do we want window decorations?
1.22      rpe        82:        if [[ -n $ILS ]]; then
1.16      halex      83:                function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; }
                     84:                function label { print -n "${WLS}$*${WLE}">/dev/tty; }
1.1       downsj     85:
                     86:                alias stripe='label "$USER@$HOST ($tty) - $PWD"'
                     87:                alias istripe='ilabel "$USER@$HOST ($tty)"'
                     88:
1.19      halex      89:                # Run stuff through this to preserve the exit code
                     90:                function _ignore { local rc=$?; "$@"; return $rc; }
                     91:
                     92:                function wftp { ilabel "ftp $*"; "ftp" "$@"; _ignore eval istripe; }
                     93:
                     94:                function wcd     { \cd "$@";     _ignore eval stripe; }
                     95:
                     96:                function wssh    { \ssh "$@";    _ignore eval 'istripe; stripe'; }
                     97:                function wtelnet { \telnet "$@"; _ignore eval 'istripe; stripe'; }
                     98:                function wsu     { \su "$@";     _ignore eval 'istripe; stripe'; }
                     99:
1.1       downsj    100:                alias su=wsu
                    101:                alias cd=wcd
                    102:                alias ftp=wftp
1.6       todd      103:                alias ssh=wssh
1.1       downsj    104:                alias telnet=wtelnet
1.18      halex     105:                eval stripe
                    106:                eval istripe
1.1       downsj    107:                PS1=$PROMPT
                    108:        fi
                    109:        alias quit=exit
                    110:        alias cls=clear
                    111:        alias logout=exit
                    112:        alias bye=exit
                    113:        alias p='ps -l'
                    114:        alias j=jobs
                    115:        alias o='fg %-'
1.20      rpe       116:        alias df='df -k'
                    117:        alias du='du -k'
1.28      tb        118:        alias rsize='eval $(resize)'
1.1       downsj    119: ;;
                    120: *)     # non-interactive
                    121: ;;
                    122: esac
                    123: # commands for both interactive and non-interactive shells
                    124:
                    125: # is $1 missing from $2 (or PATH) ?
1.16      halex     126: function no_path {
1.23      rpe       127:        eval _v="\$${2:-PATH}"
                    128:        case :$_v: in
                    129:        *:$1:*) return 1;;              # no we have it
                    130:        esac
                    131:        return 0
1.1       downsj    132: }
                    133: # if $1 exists and is not in path, append it
1.16      halex     134: function add_path {
1.23      rpe       135:        [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
1.1       downsj    136: }
                    137: # if $1 exists and is not in path, prepend it
1.16      halex     138: function pre_path {
1.23      rpe       139:        [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
1.1       downsj    140: }
                    141: # if $1 is in path, remove it
1.16      halex     142: function del_path {
1.28      tb        143:        no_path $* || eval ${2:-PATH}=$(eval echo :'$'${2:-PATH}: |
                    144:                sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;")
1.1       downsj    145: }