# # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc # # Enable "gmacs" editor mode if the user did not set an # input mode yet (for example via ${EDITOR}, ${VISUAL} or any # "set -o" flag) if [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then set -o gmacs fi # max. number of path components shown on the default prompt if [[ -z ${.sh.path_comps} ]]; then integer .sh.path_comps=3 else # is a [reasonable] number? integer x=${.sh.path_comps} (( $x < 1 )) && integer .sh.path_comps=3 unset x fi # enable multiline input mode set -o multiline # enable globstar mode (match subdirs with **/) set -o globstar # Set a default prompt (@ <"($|#) ">) if # then variable does not exist in the environment. # # Algorithm: # 1. Define "ellipsis", either Unicode #2026 for unicode locales # and "..." otherwise # ([[ "${LC_ALL}/${LANG}" = ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] # ensures that the pattern matches the leftmost sequence # containing *.UTF-8, allowing to match either LC_ALL or # LANG when LC_ALL is not set) # 2. If PWD is within HOME replace value of HOME with '~' # If the PWD is longer than 30 charatcers shorten it to 30 chars # print '#' for user "root" and '$' for normal users # Notes: # - printf "%*s\r%s" COLUMNS "") # is used at the beginning to # work around a bug in the "multiline" handling code which # causes the shell to override its own prompt when the edit # line overflows (this happens if the terminal cursor # position is not 0 when PS1 is printed). # - PS1 will initially be empty until either... # a) ... someone sets the variable # or # b) ... the prompt is displayed for the first time (default is # '$ ' for normal users and '# ' for user "root") # - The statement below will not work if someone sources /etc/ksh.kshrc # unless PS1 gets "unset" first. # - Make sure to use absolute paths (e.g. /usr/bin/hostname) to make # sure PS1 works in cases where PATH does not contain /usr/bin/ # jel: # - always enable multiline and globstar # - removed the match expression bullshit, since it has undesired # side-effects on interactive shell (changes ${.sh.match} -> unusable) # - print only last 3 components excl. a possible ~ of a path prefixed by # ${.sh.ellipses} if set (e.g. to '\u[2026]') # NOTE: the a < b || a > b is needed instead of a != b to avoid pattern # matching and thus possible change of .sh.match if [[ "$(set)" != ~(E)PS1= && -z ${PS1} ]] ; then PS1=${ printf "\033[1m${LOGNAME}@${ uname -n ; } " ; }'$( set +o xtrace +o errexit p="${PWD}" p1="${p:0:${#HOME}}" integer n=${.sh.path_comps} [[ ${p1} < ${HOME} || ${p1} > ${HOME} ]] && : || p="~${p:${#HOME}}" IFS="/" c=( ${p} ) l=${#c[@]} [[ ${p:0:1} == "~" ]] && (( l-1 == n )) && (( n++ )) if (( l > n )); then [[ -n ${.sh.ellipses} ]] && p="${.sh.ellipses}/" || p="" for (( i=l-n ; i < l ; i++ )) ; do p+="${c[$i]}/" done p=${p:0:${#p}-1} fi [[ "${LOGNAME}" == "root" ]] && p+=" # " || p+=" \$ " printf "${p}\033[0m" )' fi