Skip to content

Commit

Permalink
Merge branch 'fix/faster,shorter,better-lp_title' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dolmen committed Apr 23, 2015
2 parents d6387f2 + 2d5b3f1 commit 8605378
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
- Battery indicator:
* MacOS: many fixes to handle (all?) edge cases (Github #326)
We now have a pmset simulator to better detect regressions.
- Title:
* Fix terminal sequences that were sent in the title text (the
escaping algorithm is rewritten and now just correct).
- Misc:
* Fix bash 3 compatibility (Github #313)
- Sample configuration files:
Expand Down
22 changes: 16 additions & 6 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -1463,23 +1463,33 @@ _lp_temperature() {
##########


# Sed expression using extended regexp to remove shell codes around terminal
# escape sequences
_LP_CLEAN_ESC="$(printf "s,%q|%q,,g" "$_LP_OPEN_ESC" "$_LP_CLOSE_ESC")"
# Sed expression using extended regexp to match terminal
# escape sequences with their wrappers
# The generic solution, but unreadable:
# _LP_CLEAN_ESC="$(printf "s,%q|%q,,g" "$_LP_OPEN_ESC" "$_LP_CLOSE_ESC")"
# Hardcoded solution:
if $_LP_SHELL_bash; then
_LP_CLEAN_ESC='\\\[([^\\]+|\\[^\]])*\\\]'
else
_LP_CLEAN_ESC='%\{([^%]+|%[^}])*%\}'
fi

# Remove all colors and escape characters of the given string and return a pure text
_lp_as_text()
{
# Remove colors from the computed prompt
echo -n "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[[0-9;]*[mK]//g;$_LP_CLEAN_ESC"
# Remove all terminal sequences that we wrapped with $_LP_OPEN_ESC and
# $_LP_CLOSE_ESC.
echo -n "$1" | sed -$_LP_SED_EXTENDED "s,$_LP_CLEAN_ESC,,g"
}

_lp_title()
{
[[ "$LP_ENABLE_TITLE" != "1" ]] && return

# Get the current computed prompt as pure text
echo -n "${_LP_OPEN_ESC}${LP_TITLE_OPEN}$(_lp_as_text "$1")${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
echo -n "${_LP_OPEN_ESC}${LP_TITLE_OPEN}"
_lp_as_text "$1"
echo -n "${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
}

# Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
Expand Down

0 comments on commit 8605378

Please sign in to comment.