Optimize as $EUID can't change during the shell life

$EUID will not change during the shell life. So we can optimize color
selection at liquidprompt startup instead of testing multiple times
every time the prompt is shown.
Optimizes LP_MARK and LP_PWD.
This commit is contained in:
Olivier Mengué 2013-06-11 22:23:26 +02:00
parent a31d37edad
commit cc839487ec

View File

@ -364,8 +364,10 @@ if [[ "$EUID" -ne "0" ]] ; then # if user is not root
LP_USER="" LP_USER=""
fi fi
fi fi
else else # root!
LP_USER="${LP_COLOR_USER_ROOT}${_LP_USER_SYMBOL}${NO_COL}" LP_USER="${LP_COLOR_USER_ROOT}${_LP_USER_SYMBOL}${NO_COL}"
LP_COLOR_MARK="${LP_COLOR_MARK_ROOT}"
LP_COLOR_PATH="${LP_COLOR_PATH_ROOT}"
fi fi
@ -1305,11 +1307,6 @@ _lp_title()
# to # if root and else $ # to # if root and else $
_lp_smart_mark() _lp_smart_mark()
{ {
local color=${LP_COLOR_MARK}
if [[ "$EUID" -eq "0" ]] ; then
color=${LP_COLOR_MARK_ROOT}
fi
local mark local mark
if [[ -n "$LP_MARK_DEFAULT" ]]; then if [[ -n "$LP_MARK_DEFAULT" ]]; then
mark=$LP_MARK_DEFAULT mark=$LP_MARK_DEFAULT
@ -1333,7 +1330,7 @@ _lp_smart_mark()
elif [[ "$1" == "disabled" ]]; then elif [[ "$1" == "disabled" ]]; then
mark=$LP_MARK_DISABLED mark=$LP_MARK_DISABLED
fi fi
echo -ne "${color}${mark}${NO_COL}" echo -ne "${LP_COLOR_MARK}${mark}${NO_COL}"
} }
# insert a space on the right # insert a space on the right
@ -1498,12 +1495,9 @@ _lp_set_prompt()
# end of the prompt line: double spaces # end of the prompt line: double spaces
LP_MARK="$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPE)")" LP_MARK="$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPE)")"
# Different path color if root # The color is different if user is root
if [[ "$EUID" -ne "0" ]] ; then
LP_PWD="${LP_COLOR_PATH}${LP_PWD}${NO_COL}" LP_PWD="${LP_COLOR_PATH}${LP_PWD}${NO_COL}"
else
LP_PWD="${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}"
fi
LP_OLD_PWD="$PWD" LP_OLD_PWD="$PWD"
# if do not change of working directory but... # if do not change of working directory but...