Annotation of src/etc/ksh.kshrc, Revision 1.3
1.1 downsj 1: :
1.3 ! marc 2: # $OpenBSD: ksh.kshrc,v 1.2 1996/12/16 03:49:50 kstailey Exp $
1.1 downsj 3: #
4: # NAME:
5: # ksh.kshrc - global initialization for ksh
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
29: # use this file is hereby granted provided that
30: # the above copyright notice and this notice are
31: # left intact.
32:
33: case "$-" in
34: *i*) # we are interactive
35: # we may have su'ed so reset these
36: # NOTE: SCO-UNIX doesn't have whoami,
37: # install whoami.sh
38: USER=`whoami 2>/dev/null`
39: USER=${USER:-`id | sed 's/^[^(]*(\([^)]*\)).*/\1/'`}
1.3 ! marc 40: UID=`id -u`
1.1 downsj 41: case $UID in
42: 0) PS1S='# ';;
43: esac
44: PS1S=${PS1S:-'$ '}
45: HOSTNAME=${HOSTNAME:-`uname -n`}
46: HOST=${HOSTNAME%%.*}
47:
48: PROMPT="$USER:!$PS1S"
49: #PROMPT="<$USER@$HOST:!>$PS1S"
50: PPROMPT='$USER:$PWD:!'"$PS1S"
51: #PPROMPT='<$USER@$HOST:$PWD:!>'"$PS1S"
52: PS1=$PPROMPT
53: # $TTY is the tty we logged in on,
54: # $tty is that which we are in now (might by pty)
55: tty=`tty`
56: tty=`basename $tty`
57: TTY=${TTY:-$tty}
1.2 kstailey 58:
1.1 downsj 59: set -o emacs
60:
61: alias ls='ls -CF'
62: alias h='fc -l | more'
63: _cd() { "cd" $*; }
64: # the PD ksh is not 100% compatible
65: case "$KSH_VERSION" in
66: *PD*) # PD ksh
67: case "$TERM" in
68: pc3|pcvt*|xterm*)
69: # bind arrow keys
70: bind '^[['=prefix-2
71: bind '^XA'=up-history
72: bind '^XB'=down-history
73: bind '^XC'=forward-char
74: bind '^XD'=backward-char
75: ;;
76: esac
77: ;;
78: *) # real ksh ?
79: [ -r $HOME/.functions ] && . $HOME/.functions
80: set -o trackall
81: ;;
82: esac
83: case "$TERM" in
1.3 ! marc 84: sun*-s)
! 85: # sun console with status line
1.2 kstailey 86: if [ "$tty" != "$console" ]; then
1.1 downsj 87: # ilabel
88: ILS='\033]L'; ILE='\033\\'
89: # window title bar
90: WLS='\033]l'; WLE='\033\\'
91: fi
92: ;;
93: xterm*)
94: ILS='\033]1;'; ILE='\007'
95: WLS='\033]2;'; WLE='\007'
96: parent="`ps -ax 2>/dev/null | grep $PPID | grep -v grep`"
97: case "$parent" in
98: *telnet*)
99: export TERM=xterms;;
100: esac
101: ;;
102: *) ;;
103: esac
104: # do we want window decorations?
105: if [ "$ILS" ]; then
106: ilabel () { print -n "${ILS}$*${ILE}"; }
107: label () { print -n "${WLS}$*${WLE}"; }
108:
109: alias stripe='label "$USER@$HOST ($tty) - $PWD"'
110: alias istripe='ilabel "$USER@$HOST ($tty)"'
111:
112: wftp () { ilabel "ftp $*"; "ftp" $*; eval istripe; }
113: wcd () { _cd $*; eval stripe; }
114: wtelnet ()
115: {
116: "telnet" "$@"
117: eval istripe
118: eval stripe
119: }
120: wrlogin ()
121: {
122: "rlogin" "$@"
123: eval istripe
124: eval stripe
125: }
126: wsu ()
127: {
128: "su" "$@"
129: eval istripe
130: eval stripe
131: }
132: alias su=wsu
133: alias cd=wcd
134: alias ftp=wftp
135: alias telnet=wtelnet
136: alias rlogin=wrlogin
137: eval stripe
138: eval istripe
139: PS1=$PROMPT
140: fi
141: alias quit=exit
142: alias cls=clear
143: alias logout=exit
144: alias bye=exit
145: alias p='ps -l'
146: alias j=jobs
147: alias o='fg %-'
148: alias ls='ls -gCF'
149:
150: # add your favourite aliases here
151: OS=${OS:-`uname -s`}
152: case $OS in
153: HP-UX)
154: alias ls='ls -CF'
155: ;;
156: *BSD)
157: alias df='df -k'
158: alias du='du -k'
159: ;;
160: esac
161: alias rsize='eval `resize`'
162:
163: case "$TERM" in
164: sun*|xterm*)
165: case $tty in
166: tty[p-w]*)
167: case "$DISPLAY" in
168: "")
169: DISPLAY="`who | grep $TTY | sed -n 's/.*(\([^:)]*\)[:)].*/\1/p' | sed 's/\([a-zA-Z][^.]*\).*/\1/'`:0"
170: ;;
171: esac
172: ;;
173: esac
174: case "$DISPLAY" in
175: ozen*|:*)
176: stty erase "^?"
177: ;;
178: *)
179: stty erase "^h"
180: ;;
181: esac
182: export DISPLAY
183: ;;
184: esac
185:
186: ;;
187: *) # non-interactive
188: ;;
189: esac
190: # commands for both interactive and non-interactive shells
191:
192: # is $1 missing from $2 (or PATH) ?
193: no_path () {
194: eval _v="\$${2:-PATH}"
195: case :$_v: in
196: *:$1:*) return 1;; # no we have it
197: esac
198: return 0
199: }
200: # if $1 exists and is not in path, append it
201: add_path () {
202: [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
203: }
204: # if $1 exists and is not in path, prepend it
205: pre_path () {
206: [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
207: }
208: # if $1 is in path, remove it
209: del_path () {
210: no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
211: sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`
212: }