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