_lp_shorten_path: don't use a sub shell anymore

Instead of using a subshell, _lp_shorten_path now directly sets its
result into the LP_PWD variable.
This is not just for style, but for speed.
This commit is contained in:
Olivier Mengué 2013-12-17 00:12:14 +01:00
parent 964f77834e
commit 3ff556a759

View File

@ -510,11 +510,12 @@ unset _lp_connection
# + keep some left part of the path if asked # + keep some left part of the path if asked
_lp_shorten_path() _lp_shorten_path()
{ {
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 || -n "$PROMPT_DIRTRIM" ]] ; then if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] ; then
if $_LP_SHELL_bash; then if $_LP_SHELL_bash; then
echo "\\w" [[ -n "$PROMPT_DIRTRIM" ]] && _lp_set_dirtrim
LP_PWD="\\w"
else else
print -P '%~' LP_PWD='%~'
fi fi
return return
fi fi
@ -573,7 +574,7 @@ _lp_shorten_path()
# the maximum allowed length, # the maximum allowed length,
# so no need for '…' # so no need for '…'
# #
echo "$p" LP_PWD="$p"
elif (( pos[i] == len )) elif (( pos[i] == len ))
then then
@ -582,23 +583,22 @@ _lp_shorten_path()
# than the last part of the path, plus # than the last part of the path, plus
# ' … ' # ' … '
# #
echo "${p:0:pos[keep]+1}${mask}${p:len-max_len+mask_len}" LP_PWD="${p:0:pos[keep]+1}${mask}${p:len-max_len+mask_len}"
else else
# constraints are satisfied, at least # constraints are satisfied, at least
# some parts of the path, plus ' … ', are # some parts of the path, plus ' … ', are
# shorter than the maximum allowed size # shorter than the maximum allowed size
# #
echo "${p:0:pos[keep]+1}${mask}${p:pos[i]}" LP_PWD="${p:0:pos[keep]+1}${mask}${p:pos[i]}"
fi fi
else else
echo "$p" LP_PWD="$p"
fi fi
else # zsh else # zsh
unset p
if (( len > max_len )); then if (( len > max_len )); then
print -P "%-${LP_PATH_KEEP}~%${max_len}<${LP_MARK_SHORTEN_PATH}<%~%<<" LP_PWD="%-${LP_PATH_KEEP}~%${max_len}<${LP_MARK_SHORTEN_PATH}<%~%<<"
else else
print -P '%~' LP_PWD='%~'
fi fi
fi fi
} }
@ -627,7 +627,7 @@ _lp_set_dirtrim() {
fi fi
PROMPT_DIRTRIM=$dt PROMPT_DIRTRIM=$dt
# For debugging # For debugging
# echo $PROMPT_DIRTRIM # echo PROMPT_DIRTRIM=$PROMPT_DIRTRIM >&2
} }
# Display a ":" # Display a ":"
@ -1637,9 +1637,7 @@ _lp_set_prompt()
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="$(_lp_permissions_color)"
LP_PWD="$(_lp_shorten_path)" _lp_shorten_path # set LP_PWD
# Check that both LP_ENABLE_SHORTEN and PROMPT_DIRTRIM are set
[[ "_$LP_ENABLE_SHORTEN_PATH/$PROMPT_DIRTRIM" = _1/?* ]] && _lp_set_dirtrim
if _lp_are_vcs_enabled; then if _lp_are_vcs_enabled; then
LP_VCS="$(_lp_git_branch_color)" LP_VCS="$(_lp_git_branch_color)"