Add return value to bash prompt

This commit is contained in:
2025-04-29 15:54:59 +08:00
parent 1c69b6de79
commit e903a3a256

View File

@@ -34,7 +34,7 @@ shopt -s checkwinsize
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot) debian_chroot=$(cat /etc/debian_chroot)
fi fi
$()
# set a fancy prompt (non-color, unless we know we "want" color) # set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in case "$TERM" in
xterm*) color_prompt=yes;; xterm*) color_prompt=yes;;
@@ -72,6 +72,15 @@ xterm*|rxvt*)
;; ;;
esac esac
# Add goodies to PS1
export BASE_PS1="$PS1"
export BASE_PS1="$(echo "$BASE_PS1" | sed 's!\\\$ $!!g')"
export BASE_PS1_END='\$ '
# show return value if prompt is nonzero
export BASH_GOODIES_RETURNVAL='$([ "$?" = 0 ] && echo "" || echo " \e[31m\][$?]\[\e[0m\] ")'
PS1="${BASE_PS1}${BASH_GOODIES_RETURNVAL}${BASE_PS1_END}"
# enable color support of ls and also add handy aliases # enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"