Annotation of src/etc/ksh.kshrc, Revision 1.28
1.1 downsj 1: :
1.28 ! tb 2: # $OpenBSD: ksh.kshrc,v 1.27 2016/09/14 18:34:51 rpe 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.27 rpe 77: if ps -p $PPID -o command | grep -q telnet; then
78: export TERM=xterms
79: fi
1.1 downsj 80: ;;
81: *) ;;
82: esac
83: # do we want window decorations?
1.22 rpe 84: if [[ -n $ILS ]]; then
1.16 halex 85: function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; }
86: function label { print -n "${WLS}$*${WLE}">/dev/tty; }
1.1 downsj 87:
88: alias stripe='label "$USER@$HOST ($tty) - $PWD"'
89: alias istripe='ilabel "$USER@$HOST ($tty)"'
90:
1.19 halex 91: # Run stuff through this to preserve the exit code
92: function _ignore { local rc=$?; "$@"; return $rc; }
93:
94: function wftp { ilabel "ftp $*"; "ftp" "$@"; _ignore eval istripe; }
95:
96: function wcd { \cd "$@"; _ignore eval stripe; }
97:
98: function wssh { \ssh "$@"; _ignore eval 'istripe; stripe'; }
99: function wtelnet { \telnet "$@"; _ignore eval 'istripe; stripe'; }
100: function wsu { \su "$@"; _ignore eval 'istripe; stripe'; }
101:
1.1 downsj 102: alias su=wsu
103: alias cd=wcd
104: alias ftp=wftp
1.6 todd 105: alias ssh=wssh
1.1 downsj 106: alias telnet=wtelnet
1.18 halex 107: eval stripe
108: eval istripe
1.1 downsj 109: PS1=$PROMPT
110: fi
111: alias quit=exit
112: alias cls=clear
113: alias logout=exit
114: alias bye=exit
115: alias p='ps -l'
116: alias j=jobs
117: alias o='fg %-'
1.20 rpe 118: alias df='df -k'
119: alias du='du -k'
1.28 ! tb 120: alias rsize='eval $(resize)'
1.1 downsj 121: ;;
122: *) # non-interactive
123: ;;
124: esac
125: # commands for both interactive and non-interactive shells
126:
127: # is $1 missing from $2 (or PATH) ?
1.16 halex 128: function no_path {
1.23 rpe 129: eval _v="\$${2:-PATH}"
130: case :$_v: in
131: *:$1:*) return 1;; # no we have it
132: esac
133: return 0
1.1 downsj 134: }
135: # if $1 exists and is not in path, append it
1.16 halex 136: function add_path {
1.23 rpe 137: [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
1.1 downsj 138: }
139: # if $1 exists and is not in path, prepend it
1.16 halex 140: function pre_path {
1.23 rpe 141: [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
1.1 downsj 142: }
143: # if $1 is in path, remove it
1.16 halex 144: function del_path {
1.28 ! tb 145: no_path $* || eval ${2:-PATH}=$(eval echo :'$'${2:-PATH}: |
! 146: sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;")
1.1 downsj 147: }