From 17f3bd32ba658ddf02c29b7381fae3cb92c4478f Mon Sep 17 00:00:00 2001 From: Aurelien Requiem Date: Wed, 25 Jul 2012 10:13:47 +1000 Subject: [PATCH 1/2] added condition check to prevent sourcing the prompt if no $TERM as tput needs it --- liquidprompt.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt.bash b/liquidprompt.bash index 8403a56..97ef3af 100755 --- a/liquidprompt.bash +++ b/liquidprompt.bash @@ -35,7 +35,7 @@ # green = no changes or commits # Check for recent enough version of bash. -[ -z "$BASH_VERSION" -o -z "$PS1" ] && return; +[ -z "$BASH_VERSION" -o -z "$PS1" -o -z "$TERM" ] && return; bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} if [ $bmajor -lt 3 ] || [ $bmajor -eq 3 -a $bminor -lt 2 ]; then From cb1ea61d57bad60a3b9524aedb1c1ef451068f54 Mon Sep 17 00:00:00 2001 From: Aurelien Requiem Date: Wed, 25 Jul 2012 10:42:42 +1000 Subject: [PATCH 2/2] added variable length path to the prompt --- liquidprompt.bash | 80 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/liquidprompt.bash b/liquidprompt.bash index 97ef3af..0684c73 100755 --- a/liquidprompt.bash +++ b/liquidprompt.bash @@ -368,6 +368,80 @@ __hg_branch_color() fi } +# Simple BASH function that shortens +# a very long path for display by removing +# the left most parts and replacing them +# with a leading ... +# +# the first argument is the path +# +# the second argument is the maximum allowed +# length including the '/'s and ... +# http://hbfs.wordpress.com/2009/09/01/short-pwd-in-bash-prompts/ +# +__shorten_path() +{ + local p="$1" + local len="${#p}" + local max_len="$2" + + if [ "$len" -gt "$max_len" ] + then + # finds all the '/' in + # the path and stores their + # positions + # + local pos=() + for ((i=0;i