ksh.kshrc revision 1.21
1: 2# $OpenBSD: ksh.kshrc,v 1.21 2016/09/09 16:11:12 rpe 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 USER=`whoami 2>/dev/null` 37 USER=${USER:-`id | sed 's/^[^(]*(\([^)]*\)).*/\1/'`} 38 UID=`id -u` 39 case $UID in 40 0) PS1S='# ';; 41 esac 42 PS1S=${PS1S:-'$ '} 43 HOSTNAME=${HOSTNAME:-`uname -n`} 44 HOST=${HOSTNAME%%.*} 45 46 PROMPT="$USER:!$PS1S" 47 #PROMPT="<$USER@$HOST:!>$PS1S" 48 PPROMPT='$USER:$PWD:!'"$PS1S" 49 #PPROMPT='<$USER@$HOST:$PWD:!>'"$PS1S" 50 PS1=$PPROMPT 51 # $TTY is the tty we logged in on, 52 # $tty is that which we are in now (might by pty) 53 tty=`tty` 54 tty=`basename $tty` 55 TTY=${TTY:-$tty} 56 # $console is the system console device 57 console=$(sysctl machdep.console_device) 58 console=${console#*=} 59 60 set -o emacs 61 62 alias ls='ls -CF' 63 alias h='fc -l | more' 64 65 case "$TERM" in 66 sun*-s) 67 # sun console with status line 68 if [ "$tty" != "$console" ]; then 69 # ilabel 70 ILS='\033]L'; ILE='\033\\' 71 # window title bar 72 WLS='\033]l'; WLE='\033\\' 73 fi 74 ;; 75 xterm*) 76 ILS='\033]1;'; ILE='\007' 77 WLS='\033]2;'; WLE='\007' 78 parent="`ps -ax 2>/dev/null | grep $PPID | grep -v grep`" 79 case "$parent" in 80 *telnet*) 81 export TERM=xterms;; 82 esac 83 ;; 84 *) ;; 85 esac 86 # do we want window decorations? 87 if [ "$ILS" ]; then 88 function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; } 89 function label { print -n "${WLS}$*${WLE}">/dev/tty; } 90 91 alias stripe='label "$USER@$HOST ($tty) - $PWD"' 92 alias istripe='ilabel "$USER@$HOST ($tty)"' 93 94 # Run stuff through this to preserve the exit code 95 function _ignore { local rc=$?; "$@"; return $rc; } 96 97 function wftp { ilabel "ftp $*"; "ftp" "$@"; _ignore eval istripe; } 98 99 function wcd { \cd "$@"; _ignore eval stripe; } 100 101 function wssh { \ssh "$@"; _ignore eval 'istripe; stripe'; } 102 function wtelnet { \telnet "$@"; _ignore eval 'istripe; stripe'; } 103 function wrlogin { \rlogin "$@"; _ignore eval 'istripe; stripe'; } 104 function wsu { \su "$@"; _ignore eval 'istripe; stripe'; } 105 106 alias su=wsu 107 alias cd=wcd 108 alias ftp=wftp 109 alias ssh=wssh 110 alias telnet=wtelnet 111 alias rlogin=wrlogin 112 eval stripe 113 eval istripe 114 PS1=$PROMPT 115 fi 116 alias quit=exit 117 alias cls=clear 118 alias logout=exit 119 alias bye=exit 120 alias p='ps -l' 121 alias j=jobs 122 alias o='fg %-' 123 alias df='df -k' 124 alias du='du -k' 125 alias rsize='eval `resize`' 126;; 127*) # non-interactive 128;; 129esac 130# commands for both interactive and non-interactive shells 131 132# is $1 missing from $2 (or PATH) ? 133function no_path { 134 eval _v="\$${2:-PATH}" 135 case :$_v: in 136 *:$1:*) return 1;; # no we have it 137 esac 138 return 0 139} 140# if $1 exists and is not in path, append it 141function add_path { 142 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" 143} 144# if $1 exists and is not in path, prepend it 145function pre_path { 146 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" 147} 148# if $1 is in path, remove it 149function del_path { 150 no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: | 151 sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"` 152} 153