Merge branch 'refactor/TITLE' into develop
Major refactoring of the TITLE feature, for correctness and speed.
This commit is contained in:
commit
2d4aa430d3
51
liquidprompt
51
liquidprompt
@ -106,6 +106,11 @@ case "$LP_OS" in
|
|||||||
SunOS) _lp_CPUNUM=$( kstat -m cpu_info | grep -c "module: cpu_info" ) ;;
|
SunOS) _lp_CPUNUM=$( kstat -m cpu_info | grep -c "module: cpu_info" ) ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Extended regexp patterns for sed
|
||||||
|
# GNU/BSD sed
|
||||||
|
_LP_SED_EXTENDED=r
|
||||||
|
[[ "$LP_OS" = Darwin ]] && _LP_SED_EXTENDED=E
|
||||||
|
|
||||||
|
|
||||||
# get current load
|
# get current load
|
||||||
case "$LP_OS" in
|
case "$LP_OS" in
|
||||||
@ -357,11 +362,16 @@ esac
|
|||||||
if [[ "$TERM" == screen* ]]; then
|
if [[ "$TERM" == screen* ]]; then
|
||||||
LP_BRACKET_OPEN="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_OPEN}${NO_COL}"
|
LP_BRACKET_OPEN="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_OPEN}${NO_COL}"
|
||||||
LP_BRACKET_CLOSE="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_CLOSE}${NO_COL}"
|
LP_BRACKET_CLOSE="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_CLOSE}${NO_COL}"
|
||||||
|
(( LP_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE ))
|
||||||
|
LP_TITLE_OPEN="$LP_SCREEN_TITLE_OPEN"
|
||||||
|
LP_TITLE_CLOSE="$LP_SCREEN_TITLE_CLOSE"
|
||||||
else
|
else
|
||||||
LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}"
|
LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}"
|
||||||
LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}"
|
LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[[ "_$TERM" == _linux* ]] && LP_ENABLE_TITLE=0
|
||||||
|
|
||||||
# update_terminal_cwd is a shell function available on MacOS X Lion that
|
# update_terminal_cwd is a shell function available on MacOS X Lion that
|
||||||
# will update an icon of the directory displayed in the title of the terminal
|
# will update an icon of the directory displayed in the title of the terminal
|
||||||
# window.
|
# window.
|
||||||
@ -1467,24 +1477,16 @@ _lp_temperature() {
|
|||||||
# DESIGN #
|
# DESIGN #
|
||||||
##########
|
##########
|
||||||
|
|
||||||
|
|
||||||
|
# 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")"
|
||||||
|
|
||||||
# Remove all colors and escape characters of the given string and return a pure text
|
# Remove all colors and escape characters of the given string and return a pure text
|
||||||
_lp_as_text()
|
_lp_as_text()
|
||||||
{
|
{
|
||||||
# Remove colors from the computed prompt
|
# Remove colors from the computed prompt
|
||||||
case "$LP_OS" in
|
echo -n "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[[0-9;]*[mK]//g;$_LP_CLEAN_ESC"
|
||||||
Linux|FreeBSD|OpenBSD|SunOS) local pst="$(echo $1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
|
||||||
Darwin) local pst="$(echo $1 | sed -E "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
# Remove escape sequences
|
|
||||||
# FIXME check the zsh compatibility
|
|
||||||
# pst=$(echo $pst | sed "s,\\\\\\[\|\\\\\\],,g")
|
|
||||||
local op="$(printf "%q" "$_LP_OPEN_ESC")"
|
|
||||||
local cl="$(printf "%q" "$_LP_CLOSE_ESC")"
|
|
||||||
pst="$(echo $pst | sed "s,$op\|$cl,,g")" # replace all open _or_ close tags with nothing
|
|
||||||
|
|
||||||
echo -n "$pst"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_lp_title()
|
_lp_title()
|
||||||
@ -1492,24 +1494,7 @@ _lp_title()
|
|||||||
[[ "$LP_ENABLE_TITLE" != "1" ]] && return
|
[[ "$LP_ENABLE_TITLE" != "1" ]] && return
|
||||||
|
|
||||||
# Get the current computed prompt as pure text
|
# Get the current computed prompt as pure text
|
||||||
local txt="$(_lp_as_text "$1")"
|
echo -n "${_LP_OPEN_ESC}${LP_TITLE_OPEN}$(_lp_as_text "$1")${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
||||||
|
|
||||||
# Use it in the window's title
|
|
||||||
# Escapes whill tells bash to ignore the non-printing control characters when calculating the width of the prompt.
|
|
||||||
# Otherwise line editing commands will mess the cursor positionning
|
|
||||||
case "$TERM" in
|
|
||||||
screen*)
|
|
||||||
[[ "$LP_ENABLE_SCREEN_TITLE" != "1" ]] && return
|
|
||||||
local title="${LP_SCREEN_TITLE_OPEN}${txt}${LP_SCREEN_TITLE_CLOSE}"
|
|
||||||
;;
|
|
||||||
linux*)
|
|
||||||
local title=""
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
local title="${_LP_OPEN_ESC}${LP_TITLE_OPEN}${txt}${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo -n "${title}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
|
# Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
|
||||||
@ -1722,7 +1707,7 @@ _lp_set_prompt()
|
|||||||
source "$LP_PS1_FILE"
|
source "$LP_PS1_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $LP_PS1 ]] ; then
|
if [[ -z "$LP_PS1" ]] ; then
|
||||||
# add title escape time, jobs, load and battery
|
# add title escape time, jobs, load and battery
|
||||||
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_TEMP}${LP_JOBS}"
|
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_TEMP}${LP_JOBS}"
|
||||||
# add user, host and permissions colon
|
# add user, host and permissions colon
|
||||||
|
@ -122,7 +122,8 @@ LP_ENABLE_TEMP=1
|
|||||||
LP_TIME_ANALOG=0
|
LP_TIME_ANALOG=0
|
||||||
|
|
||||||
# Use the liquid prompt as the title of the terminal window
|
# Use the liquid prompt as the title of the terminal window
|
||||||
# This may not work properly on exotic terminals, thus the
|
# The content is not customizable, the implementation is very basic,
|
||||||
|
# and this may not work properly on exotic terminals, thus the
|
||||||
# recommended value is 0
|
# recommended value is 0
|
||||||
# See LP_TITLE_OPEN and LP_TITLE_CLOSE to change escape characters to adapt this
|
# See LP_TITLE_OPEN and LP_TITLE_CLOSE to change escape characters to adapt this
|
||||||
# feature to your specific terminal.
|
# feature to your specific terminal.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user