diff --git a/liquidprompt.bash b/liquidprompt.bash index 8403a56..0684c73 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 @@ -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