mate-user-guide: update to 1.16.0
[unleashed-userland.git] / components / ksh93 / ksh.kshrc
blobdbc4864d0cec0af5faf7c4bb359244a129fc70ed
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
12 # "set -o" flag)
13 if [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then
14         set -o gmacs
15         # enable multiline input mode
16         set -o multiline
17         # enable globstar mode (match subdirs with **/)
18         set -o globstar
21 # Set a default prompt (<username>@<hostname>:<path><"($|#) ">) if
22 # then variable does not exist in the environment.
24 # Algorithm:
25 # 1. Define "ellipsis", either Unicode #2026 for unicode locales
26 # and "..." otherwise
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
34 # Notes:
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
42 #       or
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)"
53                 ellip="${
54                         [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] &&
55                                 printf "\u[2026]\n" || print "..." ; }"
56                 p="${PWD/~(El)${HOME}/\~}"
57                 (( ${#p} > 30 )) &&
58                         print -r -n -- "${ellip}${p:${#p}-30:30}" ||
59                         print -r -n -- "${p}"
60                 [[ "${LOGNAME}" == "root" ]] && print -n "# " || print -n "\$ "
61                 )'