Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.0 KiB

22 years ago
  1. :
  2. # $OpenBSD: ksh.kshrc,v 1.19 2014/07/11 21:12:39 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. # RCSid:
  21. # $From: ksh.kshrc,v 1.4 1992/12/05 13:14:48 sjg Exp $
  22. #
  23. # @(#)Copyright (c) 1991 Simon J. Gerraty
  24. #
  25. # This file is provided in the hope that it will
  26. # be of use. There is absolutely NO WARRANTY.
  27. # Permission to copy, redistribute or otherwise
  28. # use this file is hereby granted provided that
  29. # the above copyright notice and this notice are
  30. # left intact.
  31. case "$-" in
  32. *i*) # we are interactive
  33. # we may have su'ed so reset these
  34. # NOTE: SCO-UNIX doesn't have whoami,
  35. # install whoami.sh
  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. PROMPT="$USER:!$PS1S"
  46. #PROMPT="<$USER@$HOST:!>$PS1S"
  47. PPROMPT='$USER:$PWD:!'"$PS1S"
  48. #PPROMPT='<$USER@$HOST:$PWD:!>'"$PS1S"
  49. PS1=$PPROMPT
  50. # $TTY is the tty we logged in on,
  51. # $tty is that which we are in now (might by pty)
  52. tty=`tty`
  53. tty=`basename $tty`
  54. TTY=${TTY:-$tty}
  55. set -o emacs
  56. alias ls='ls -CF'
  57. alias h='fc -l | more'
  58. # the PD ksh is not 100% compatible
  59. case "$KSH_VERSION" in
  60. *PD*) # PD ksh
  61. ;;
  62. *) # real ksh ?
  63. [ -r $HOME/.functions ] && . $HOME/.functions
  64. set -o trackall
  65. ;;
  66. esac
  67. case "$TERM" in
  68. sun*-s)
  69. # sun console with status line
  70. if [ "$tty" != "$console" ]; then
  71. # ilabel
  72. ILS='\033]L'; ILE='\033\\'
  73. # window title bar
  74. WLS='\033]l'; WLE='\033\\'
  75. fi
  76. ;;
  77. xterm*)
  78. ILS='\033]1;'; ILE='\007'
  79. WLS='\033]2;'; WLE='\007'
  80. parent="`ps -ax 2>/dev/null | grep $PPID | grep -v grep`"
  81. case "$parent" in
  82. *telnet*)
  83. export TERM=xterms;;
  84. esac
  85. ;;
  86. *) ;;
  87. esac
  88. # do we want window decorations?
  89. if [ "$ILS" ]; then
  90. function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; }
  91. function label { print -n "${WLS}$*${WLE}">/dev/tty; }
  92. alias stripe='label "$USER@$HOST ($tty) - $PWD"'
  93. alias istripe='ilabel "$USER@$HOST ($tty)"'
  94. # Run stuff through this to preserve the exit code
  95. function _ignore { local rc=$?; "$@"; return $rc; }
  96. function wftp { ilabel "ftp $*"; "ftp" "$@"; _ignore eval istripe; }
  97. function wcd { \cd "$@"; _ignore eval stripe; }
  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. alias su=wsu
  103. alias cd=wcd
  104. alias ftp=wftp
  105. alias ssh=wssh
  106. alias telnet=wtelnet
  107. alias rlogin=wrlogin
  108. eval stripe
  109. eval istripe
  110. PS1=$PROMPT
  111. fi
  112. alias quit=exit
  113. alias cls=clear
  114. alias logout=exit
  115. alias bye=exit
  116. alias p='ps -l'
  117. alias j=jobs
  118. alias o='fg %-'
  119. # add your favourite aliases here
  120. OS=${OS:-`uname -s`}
  121. case $OS in
  122. HP-UX)
  123. alias ls='ls -CF'
  124. ;;
  125. *BSD)
  126. alias df='df -k'
  127. alias du='du -k'
  128. ;;
  129. esac
  130. alias rsize='eval `resize`'
  131. ;;
  132. *) # non-interactive
  133. ;;
  134. esac
  135. # commands for both interactive and non-interactive shells
  136. # is $1 missing from $2 (or PATH) ?
  137. function no_path {
  138. eval _v="\$${2:-PATH}"
  139. case :$_v: in
  140. *:$1:*) return 1;; # no we have it
  141. esac
  142. return 0
  143. }
  144. # if $1 exists and is not in path, append it
  145. function add_path {
  146. [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
  147. }
  148. # if $1 exists and is not in path, prepend it
  149. function pre_path {
  150. [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
  151. }
  152. # if $1 is in path, remove it
  153. function del_path {
  154. no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
  155. sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`
  156. }