From 5e92af959abcd9bec98d7df49026ba7a2c16864d Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 11:28:21 +0000 Subject: [PATCH] Attempt to no break existing installs --- themes/liquidprompt/liquidprompt.theme.bash | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 3e5ff013..9631cab7 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -21,7 +21,7 @@ export LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75} export LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60} export LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80} - +unset _lp_legacy _lp_escape __lp_escape source "$targetdir/liquidprompt" prompt() { true; } export PS2=" ┃ " @@ -29,23 +29,37 @@ export LP_PS1_PREFIX="┌─" export LP_PS1_POSTFIX="\n└▪ " export LP_ENABLE_RUNTIME=0 +_lp_legacy() +{ + type -t _lp_escape &> /dev/null +} + +_lp_legacy && __lp_escape() +{ + ret="$(_lp_escape "$@")" +} + _lp_git_branch() { (( LP_ENABLE_GIT )) || return \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return - local branch ret + local commit branch ret + + commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" + # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then - __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + __lp_escape "$commit:${branch#refs/heads/}" lp_vcs_branch="$ret" else # In detached head state, use commit instead # No escape needed - lp_vcs_branch="$(\git rev-parse --short -q HEAD 2>/dev/null)" + lp_vcs_branch="$commit" fi + _lp_legacy && echo $lp_vcs_branch || return 0 } _lp_time() {