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