1: 2# $OpenBSD: ksh.kshrc,v 1.18 2014/07/11 16:41:16 halex 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 ;; 67 *) # real ksh ? 68 [ -r $HOME/.functions ] && . $HOME/.functions 69 set -o trackall 70 ;; 71 esac 72 case "$TERM" in 73 sun*-s) 74 # sun console with status line 75 if [ "$tty" != "$console" ]; then 76 # ilabel 77 ILS='\033]L'; ILE='\033\\' 78 # window title bar 79 WLS='\033]l'; WLE='\033\\' 80 fi 81 ;; 82 xterm*) 83 ILS='\033]1;'; ILE='\007' 84 WLS='\033]2;'; WLE='\007' 85 parent="`ps -ax 2>/dev/null | grep $PPID | grep -v grep`" 86 case "$parent" in 87 *telnet*) 88 export TERM=xterms;; 89 esac 90 ;; 91 *) ;; 92 esac 93 # do we want window decorations? 94 if [ "$ILS" ]; then 95 function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; } 96 function label { print -n "${WLS}$*${WLE}">/dev/tty; } 97 98 alias stripe='label "$USER@$HOST ($tty) - $PWD"' 99 alias istripe='ilabel "$USER@$HOST ($tty)"' 100 101 function wftp { ilabel "ftp $*"; "ftp" "$@"; eval istripe; } 102 function wcd { \cd "$@" && eval stripe; } 103 function wssh 104 { 105 local rc 106 "ssh" "$@" 107 rc=$? 108 eval istripe 109 eval stripe 110 return $rc 111 } 112 function wtelnet 113 { 114 local rc 115 "telnet" "$@" 116 rc=$? 117 eval istripe 118 eval stripe 119 return $rc 120 } 121 function wrlogin 122 { 123 local rc 124 "rlogin" "$@" 125 rc=$? 126 eval istripe 127 eval stripe 128 return $rc 129 } 130 function wsu 131 { 132 local rc 133 "su" "$@" 134 rc=$? 135 eval istripe 136 eval stripe 137 return $rc 138 } 139 alias su=wsu 140 alias cd=wcd 141 alias ftp=wftp 142 alias ssh=wssh 143 alias telnet=wtelnet 144 alias rlogin=wrlogin 145 eval stripe 146 eval istripe 147 PS1=$PROMPT 148 fi 149 alias quit=exit 150 alias cls=clear 151 alias logout=exit 152 alias bye=exit 153 alias p='ps -l' 154 alias j=jobs 155 alias o='fg %-' 156 157# add your favourite aliases here 158 OS=${OS:-`uname -s`} 159 case $OS in 160 HP-UX) 161 alias ls='ls -CF' 162 ;; 163 *BSD) 164 alias df='df -k' 165 alias du='du -k' 166 ;; 167 esac 168 alias rsize='eval `resize`' 169;; 170*) # non-interactive 171;; 172esac 173# commands for both interactive and non-interactive shells 174 175# is $1 missing from $2 (or PATH) ? 176function no_path { 177 eval _v="\$${2:-PATH}" 178 case :$_v: in 179 *:$1:*) return 1;; # no we have it 180 esac 181 return 0 182} 183# if $1 exists and is not in path, append it 184function add_path { 185 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" 186} 187# if $1 exists and is not in path, prepend it 188function pre_path { 189 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" 190} 191# if $1 is in path, remove it 192function del_path { 193 no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: | 194 sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"` 195} 196