From 10a3ecb17c89bdd66da68ec4ee57c2b00ddf2d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 19:08:21 +0100 Subject: [PATCH 1/7] Fix more quoting shit, to fix LP_ENABLE_TITLE --- liquidprompt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liquidprompt b/liquidprompt index d67e6cd..33b2844 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1482,7 +1482,7 @@ _lp_as_text() # 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 + pst="$(echo "$pst" | sed "s,$op\|$cl,,g")" # replace all open _or_ close tags with nothing echo -n "$pst" } @@ -1722,7 +1722,7 @@ _lp_set_prompt() source "$LP_PS1_FILE" fi - if [[ -z $LP_PS1 ]] ; then + if [[ -z "$LP_PS1" ]] ; then # add title escape time, jobs, load and battery PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_TEMP}${LP_JOBS}" # add user, host and permissions colon From e883c8e41dc13b7ced12fe4a41b04aaccbbb33f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 19:14:48 +0100 Subject: [PATCH 2/7] Fix more bad code for LP_ENABLE_TITLE Fix one more portability hack that was really inefficient. --- liquidprompt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/liquidprompt b/liquidprompt index 33b2844..088a37b 100755 --- a/liquidprompt +++ b/liquidprompt @@ -106,6 +106,11 @@ case "$LP_OS" in SunOS) _lp_CPUNUM=$( kstat -m cpu_info | grep -c "module: cpu_info" ) ;; esac +# Extended regexp patterns for sed +# GNU/BSD sed +_LP_SED_EXTENDED=r +[[ "$LP_OS" = Darwin ]] && _LP_SED_EXTENDED=E + # get current load case "$LP_OS" in @@ -1471,11 +1476,8 @@ _lp_temperature() { _lp_as_text() { # Remove colors from the computed prompt - case "$LP_OS" in - 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 - + local pst + pst="$(echo "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # Remove escape sequences # FIXME check the zsh compatibility From 9c862aa8968877378e7a650ef8822d2100ae9d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 19:19:35 +0100 Subject: [PATCH 3/7] More warnings about LP_ENABLE_TITLE in the config example --- liquidpromptrc-dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist index fd75bf2..d47c338 100644 --- a/liquidpromptrc-dist +++ b/liquidpromptrc-dist @@ -122,7 +122,8 @@ LP_ENABLE_TEMP=1 LP_TIME_ANALOG=0 # 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 # See LP_TITLE_OPEN and LP_TITLE_CLOSE to change escape characters to adapt this # feature to your specific terminal. From d91e1422b07ffb7dc0c371e00f9ba4c0e4186571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 21:47:20 +0100 Subject: [PATCH 4/7] Fix regexp for LP_ENABLE_TITLE LP_ENABLE_TITLE is now fixed, at least on GNU/Linux with gnome-terminal. --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 088a37b..19a84f0 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1477,7 +1477,7 @@ _lp_as_text() { # Remove colors from the computed prompt local pst - pst="$(echo "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" + pst="$(echo "$1" | sed -$_LP_SED_EXTENDED 's/\x1B\[[0-9;]*[mK]//g')" # Remove escape sequences # FIXME check the zsh compatibility From 6aa43e140e3e0d46547e5eab7a1a96fc1513f991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 22:41:08 +0100 Subject: [PATCH 5/7] Move $TERM checks out of _lp_title Move $TERM checks for the TITLE feature (LP_ENABLE_TITLE) from runtime to init time as the terminal will not change during the shell's life. --- liquidprompt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/liquidprompt b/liquidprompt index 19a84f0..02e694a 100755 --- a/liquidprompt +++ b/liquidprompt @@ -362,11 +362,14 @@ esac if [[ "$TERM" == screen* ]]; then 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_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE )) else LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}" LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}" fi +[[ "_$TERM" == _linux* ]] && LP_ENABLE_TITLE=0 + # 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 # window. From 5d93b64c6a3b256848298a9577681bf93931b5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 27 Dec 2013 23:56:51 +0100 Subject: [PATCH 6/7] Refactor _lp_title Major refactoring of the TITLE feature to move all $TERM checks to init time. The _lp_title function is now reduced to two lines. --- liquidprompt | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/liquidprompt b/liquidprompt index 02e694a..1bcfb73 100755 --- a/liquidprompt +++ b/liquidprompt @@ -363,6 +363,8 @@ if [[ "$TERM" == screen* ]]; then 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_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE )) + LP_TITLE_OPEN="$LP_SCREEN_TITLE_OPEN" + LP_TITLE_CLOSE="$LP_SCREEN_TITLE_CLOSE" else LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}" LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}" @@ -1497,24 +1499,7 @@ _lp_title() [[ "$LP_ENABLE_TITLE" != "1" ]] && return # Get the current computed prompt as pure text - local txt="$(_lp_as_text "$1")" - - # 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}" + echo -n "${_LP_OPEN_ESC}${LP_TITLE_OPEN}$(_lp_as_text "$1")${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}" } # Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion From f4c20b05fc0d64379d4eb77b3511b3fbbd367ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Sat, 28 Dec 2013 00:29:33 +0100 Subject: [PATCH 7/7] Refactor _lp_as_text for speed Uses 'sed' once instead of 2 ; move building of the sed program from ruuntime to init time. --- liquidprompt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/liquidprompt b/liquidprompt index 1bcfb73..22207bd 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1477,21 +1477,16 @@ _lp_temperature() { # 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 _lp_as_text() { # Remove colors from the computed prompt - local pst - pst="$(echo "$1" | sed -$_LP_SED_EXTENDED 's/\x1B\[[0-9;]*[mK]//g')" - - # 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" + echo -n "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[[0-9;]*[mK]//g;$_LP_CLEAN_ESC" } _lp_title()