Refactor LP_PERM

This commit is contained in:
Olivier Mengué 2014-01-06 21:38:15 +01:00
parent 2ddd3bf500
commit 96e42929a6

View File

@ -389,6 +389,9 @@ else
_LP_TERM_UPDATE_DIR=: _LP_TERM_UPDATE_DIR=:
fi fi
# Default value for LP_PERM when LP_ENABLE_PERM is 0
LP_PERM=: # without color
# Escape the given strings # Escape the given strings
# Must be used for all strings that may comes from remote sources, # Must be used for all strings that may comes from remote sources,
@ -611,22 +614,6 @@ _lp_set_dirtrim() {
# echo PROMPT_DIRTRIM=$PROMPT_DIRTRIM >&2 # echo PROMPT_DIRTRIM=$PROMPT_DIRTRIM >&2
} }
# Display a ":"
# colored in green if user have write permission on the current directory
# colored in red if it have not.
_lp_permissions_color()
{
if [[ "$LP_ENABLE_PERM" != 1 ]]; then
echo : # without color
else
if [[ -w "${PWD}" ]]; then
echo "${LP_COLOR_WRITE}:${NO_COL}"
else
echo "${LP_COLOR_NOWRITE}:${NO_COL}"
fi
fi
}
# Display the current Python virtual environnement, if available. # Display the current Python virtual environnement, if available.
_lp_virtualenv() _lp_virtualenv()
{ {
@ -1603,7 +1590,18 @@ _lp_set_prompt()
LP_VCS="" LP_VCS=""
LP_VCS_TYPE="" LP_VCS_TYPE=""
# LP_HOST is a global set at load time # LP_HOST is a global set at load time
LP_PERM="$(_lp_permissions_color)"
# LP_PERM: shows a ":"
# - colored in green if user has write permission on the current dir
# - colored in red if not
if [[ "$LP_ENABLE_PERM" = 1 ]]; then
if [[ -w "${PWD}" ]]; then
LP_PERM="${LP_COLOR_WRITE}:${NO_COL}"
else
LP_PERM="${LP_COLOR_NOWRITE}:${NO_COL}"
fi
fi
_lp_shorten_path # set LP_PWD _lp_shorten_path # set LP_PWD
if _lp_are_vcs_enabled; then if _lp_are_vcs_enabled; then