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.

149 lines
3.6 KiB

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