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