Skip to content

Commit

Permalink
Merge branch 'optimize/LP_PWD' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dolmen committed Dec 21, 2015
2 parents 229920a + 9fed0a1 commit 7602c09
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
* Clear GREP_OPTIONS and skip 'grep' aliases (GitHub #372)
- Shortened path:
* Fix bugs when $PWD contains spaces or special chars (GitHub #369)
* Optimize implementation in case of LP_PATH_KEEP=-1 : LP_PWD
becomes static (related to GitHub #256, #336)
* Optimize implementation in case LP_ENABLE_SHORTEN_PATH=0
* Optimize implementation in case LP_ENABLE_SHORTEN_PATH=0 on bash
with PROMPT_DIRTRIM
- Sample configuration files:
* example.bashrc: major fixes
- The last statement of liquidprompt did not return 0 (GitHub #360,#361)
Expand All @@ -77,7 +82,7 @@
(@hcgraf), William P. Riley-Land (@wprl), Dave Rigby (@daverigby),
Ned Batchelder (@nedbat), Fabien Marty (@thefab), Alessio Garzi
(@Ozzyboshi), Roger Huang (@rhuang2014), Sebastian Bremicker
(@sebrem)...
(@sebrem), Alex Prengere ()...
... for their patches or bug reports.

1.9 2014-11-12 dolmen (Olivier Mengué)
Expand Down
44 changes: 35 additions & 9 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ if test -n "${BASH_VERSION-}" -a -n "$PS1" ; then
_LP_SHELL_zsh=false
_LP_OPEN_ESC="\["
_LP_CLOSE_ESC="\]"

_LP_USER_SYMBOL="\u"
_LP_HOST_SYMBOL="\h"
_LP_FQDN_SYMBOL="\H"
_LP_TIME_SYMBOL="\t"
_LP_MARK_SYMBOL='\$'
_LP_FIRST_INDEX=0
_LP_PWD_SYMBOL="\\w"
_LP_DIR_SYMBOL="\\W"

_LP_FIRST_INDEX=0
_LP_PERCENT='%' # must be escaped on zsh
_LP_BACKSLASH='\\' # must be escaped on bash
# Disable the DEBUG trap used by the RUNTIME feature
Expand All @@ -86,15 +89,18 @@ elif test -n "${ZSH_VERSION-}" ; then
_LP_SHELL_zsh=true
_LP_OPEN_ESC="%{"
_LP_CLOSE_ESC="%}"

_LP_USER_SYMBOL="%n"
_LP_HOST_SYMBOL="%m"
_LP_FQDN_SYMBOL="%M"
_LP_TIME_SYMBOL="%*"
_LP_MARK_SYMBOL='%(!.#.%%)'
_LP_PWD_SYMBOL="%~"
_LP_DIR_SYMBOL="%~1"

_LP_FIRST_INDEX=1
_LP_PERCENT='%%'
_LP_BACKSLASH="\\"
_LP_PWD_SYMBOL="%~"

# For ZSH, autoload required functions
autoload -Uz add-zsh-hook
Expand Down Expand Up @@ -623,10 +629,9 @@ _lp_shorten_path()
{

if (( ! LP_ENABLE_SHORTEN_PATH )); then
LP_PWD="$LP_PATH_DEFAULT"
if $_LP_SHELL_bash; then
[[ -n "$PROMPT_DIRTRIM" ]] && _lp_set_dirtrim
fi
# We are not supposed to come here often as this case is already
# optimized at install time
LP_PWD="${LP_COLOR_PATH}${LP_PATH_DEFAULT}$NOCOL"
return
fi

Expand Down Expand Up @@ -679,13 +684,34 @@ _lp_shorten_path()
fi
# Escape special chars
if $_LP_SHELL_bash; then
LP_PWD="${ret//\\/\\\\}"
LP_PWD="${LP_COLOR_PATH}${ret//\\/\\\\}$NOCOL"
else # zsh
LP_PWD="${ret//\%/%%}"
LP_PWD="${LP_COLOR_PATH}${ret//\%/%%}$NOCOL"
fi
}

# In Bash shells, PROMPT_DIRTRIM is the number of directory to keep at the end
if (( LP_ENABLE_SHORTEN_PATH )); then
if (( LP_PATH_KEEP == -1 )); then
# _lp_shorten_path becomes a noop
_lp_shorten_path()
{
:
}
# Will never change
LP_PWD="${LP_COLOR_PATH}${_LP_DIR_SYMBOL}$NOCOL"
fi
else
# Will never change
LP_PWD="${LP_COLOR_PATH}${LP_PATH_DEFAULT}$NOCOL"

if $_LP_SHELL_bash && [[ -n "$PROMPT_DIRTRIM" ]]; then
unset -f _lp_shorten_path
alias _lp_shorten_path=_lp_set_dirtrim
fi
fi


# In Bash shells, PROMPT_DIRTRIM is the number of directories to keep at the end
# of the displayed path (if "\w" is present in the PS1 var).
# Liquid Prompt can calculate this number under two conditions, path shortening
# must be disabled and PROMPT_DIRTRIM must be already set.
Expand Down

0 comments on commit 7602c09

Please sign in to comment.