.profile: Update variable names in our PS1 command to avoid clobbering

This commit is contained in:
Salt 2020-11-10 10:06:32 -06:00
parent a3f24f4b79
commit d2900fee75

View File

@ -331,59 +331,59 @@ _ps1bash() {
fg_bold="\[\e[1m\]"
# Add hostname prefix in SSH sessions
unset prefix
unset _prefix
# Alert if in an SSH session
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
prefix="${fg_bold}${fg_red}$(hostname -s)${r}${fg_red}:${r}${prefix}"
_prefix="${fg_bold}${fg_red}$(hostname -s)${r}${fg_red}:${r}${_prefix}"
elif [ "$USER" != "salt" ]; then
prefix="${fg_bold}${fg_yellow}$USER${r}${fg_yellow}:${r}${prefix}"
_prefix="${fg_bold}${fg_yellow}$USER${r}${fg_yellow}:${r}${_prefix}"
fi
# Change PWD color depending on the shell
case $0 in
*bash)
prefix="${prefix}${fg_blue}"
_prefix="${_prefix}${fg_blue}"
;;
*ksh)
prefix="${prefix}${fg_green}"
_prefix="${_prefix}${fg_green}"
;;
*)
;;
esac
# Show the tilde instead of $HOME
cpwd='\w'
_cpwd='\w'
# Show read-only status in certain directories
if [ "$UID" = 0 ]; then
# Root gets the usual "#" prompt
prompt="${fg_red}#${r}"
_prompt="${fg_red}#${r}"
elif ! [ -d "$PWD" ]; then
# Something very bad has happened to our PWD, probably got deleted
prompt="${bg_red}${fg_black}!${r}"
_prompt="${bg_red}${fg_black}!${r}"
elif ! [ -r "$PWD" ]; then
# Guess we lost privileges
prompt="${fg_red}"'$'"${r}"
_prompt="${fg_red}"'$'"${r}"
elif ! [ -x "$PWD" ]; then
# Missing execution perms
if [ -w "$PWD" ]; then
# Fixable
prompt="${bg_blue}${fg_black}"'$'"${r}"
_prompt="${bg_blue}${fg_black}"'$'"${r}"
else
# Unfixable
prompt="${bg_yellow}${fg_black}"'$'"${r}"
_prompt="${bg_yellow}${fg_black}"'$'"${r}"
fi
elif ! [ -w "$PWD" ]; then
# Can't write is really common but also good to know
prompt="${fg_magenta}"'~'"${r}"
_prompt="${fg_magenta}"'~'"${r}"
else
# Otherwise we should be fine
prompt="${fg_green}"'$'"${r}"
_prompt="${fg_green}"'$'"${r}"
fi
# Alert us if the last command failed
unset fail
unset _fail
if ! [ "$exitcode" = "0" ]; then
fail="${fg_bold}${fg_red}?"
_fail="${fg_bold}${fg_red}?"
fi
# shellcheck disable=2059
PS1="[${prefix}${cpwd}${r}]${fail}${r}${prompt}${r} "
PS1="[${_prefix}${_cpwd}${r}]${_fail}${r}${_prompt}${r} "
}
# And export our PS1