--- usr/src/cmd/nsadmin/ksh.kshrc Thu Dec 16 02:30:32 2010 +++ /etc/ksh.kshrc Mon Nov 25 19:27:36 2013 @@ -28,18 +28,28 @@ # This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc # -# Enable "gmacs"+"multiline" editor mode if the user did not set an +# 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 - # enable multiline input mode - set -o multiline - # enable globstar mode (match subdirs with **/) - set -o globstar 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 +# Set a default prompt (@ <"($|#) ">) if # then variable does not exist in the environment. # # Algorithm: @@ -67,17 +77,34 @@ # 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/ -if [[ "$(set)" != ~(E)PS1= && "${PS1}" == '' ]] ; then - PS1='$(set +o xtrace +o errexit - printf "%*s\r%s" COLUMNS "" - printf "%s@%s:" "${LOGNAME}" "$(/usr/bin/hostname)" - ellip="${ - [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] && - printf "\u[2026]\n" || print "..." ; }" - p="${PWD/~(El)${HOME}/\~}" - (( ${#p} > 30 )) && - print -r -n -- "${ellip}${p:${#p}-30:30}" || - print -r -n -- "${p}" - [[ "${LOGNAME}" == "root" ]] && print -n "# " || print -n "\$ " - )' +# 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]') +# One may modify it by writing e.g. ".sh.path_comps=3; .sh.ellipses='*'" +# into its ~/.kshrc +# 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}@${ /usr/bin/hostname ; } " ; }'$( + 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