2 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3 # Use is subject to license terms.
7 # This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc
10 # Enable "gmacs"+"multiline" editor mode if the user did not set an
11 # input mode yet (for example via ${EDITOR}, ${VISUAL} or any
13 if [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then
15 # enable multiline input mode
17 # enable globstar mode (match subdirs with **/)
21 # Set a default prompt (<username>@<hostname>:<path><"($|#) ">) if
22 # then variable does not exist in the environment.
25 # 1. Define "ellipsis", either Unicode #2026 for unicode locales
27 # ([[ "${LC_ALL}/${LANG}" = ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]]
28 # ensures that the pattern matches the leftmost sequence
29 # containing *.UTF-8, allowing to match either LC_ALL or
30 # LANG when LC_ALL is not set)
31 # 2. If PWD is within HOME replace value of HOME with '~'
32 # If the PWD is longer than 30 charatcers shorten it to 30 chars
33 # print '#' for user "root" and '$' for normal users
35 # - printf "%*s\r%s" COLUMNS "") # is used at the beginning to
36 # work around a bug in the "multiline" handling code which
37 # causes the shell to override its own prompt when the edit
38 # line overflows (this happens if the terminal cursor
39 # position is not 0 when PS1 is printed).
40 # - PS1 will initially be empty until either...
41 # a) ... someone sets the variable
43 # b) ... the prompt is displayed for the first time (default is
44 # '$ ' for normal users and '# ' for user "root")
45 # - The statement below will not work if someone sources /etc/ksh.kshrc
46 # unless PS1 gets "unset" first.
47 # - Make sure to use absolute paths (e.g. /usr/bin/hostname) to make
48 # sure PS1 works in cases where PATH does not contain /usr/bin/
49 if [[ "$(set)" != ~(E)PS1= && "${PS1}" == '' ]] ; then
50 PS1='$(set +o xtrace +o errexit
51 printf "%*s\r%s" COLUMNS ""
52 printf "%s@%s:" "${LOGNAME}" "$(/usr/bin/hostname)"
54 [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] &&
55 printf "\u[2026]\n" || print "..." ; }"
56 p="${PWD/~(El)${HOME}/\~}"
58 print -r -n -- "${ellip}${p:${#p}-30:30}" ||
60 [[ "${LOGNAME}" == "root" ]] && print -n "# " || print -n "\$ "