summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2008-03-11 17:48:45 +0100
committerHugues Hiegel <hugues@hiegel.fr>2008-03-11 21:23:10 +0100
commit516f2e67926b84b1ae698471b0fe77b5d9cc1ffb (patch)
tree6bb28ccd96ee2a0fec4ec7510b95384521896f81
parent2b94d6a55e54e2a1abf86c82e03bcd4b1448df50 (diff)
Better re-calculation of space left for path.
TODO : truncate the gitbranch to 8 char. max. - the code is not perfect yet, so it has been de-activated for the time. -
-rw-r--r--11_Prompts.zsh40
1 files changed, 31 insertions, 9 deletions
diff --git a/11_Prompts.zsh b/11_Prompts.zsh
index 8e755cc..671f86d 100644
--- a/11_Prompts.zsh
+++ b/11_Prompts.zsh
@@ -137,10 +137,6 @@ old_precmd()
MAILSTATEXPAND=$(expand_text "$MAILSTAT")
MAILSTATSIZE=${#MAILSTATEXPAND}
- # get git status
- GITBRANCH=$(get_git_branch)
- GITBRANCH=${GITBRANCH:+$C_$COLOR_DOUBLEDOT$_C:$C_"$(get_git_status)"$_C$GITBRANCH}
-
# First line of prompt, calculation of the remaining place
spaceleft=$((1 + $COLUMNS - $ERRORSIZE - $MAILSTATSIZE - $DATESIZE))
@@ -149,14 +145,40 @@ old_precmd()
do
HBAR=$HBAR-
done
- #
+
+ ##
## Second line of prompt : don't let the path garbage the entire line
+ ##
+
+ # get git status
+ #
+ GITBRANCH=$(get_git_branch)
+ GITBRANCHSIZE=${#GITBRANCH}
+ [ $GITBRANCHSIZE -gt 0 ] && GITBRANCHSIZE=$(($GITBRANCHSIZE + 1))
+ GITBRANCH=${GITBRANCH:+$C_$COLOR_DOUBLEDOT$_C:$C_"$(get_git_status)"$_C$GITBRANCH}
+
MY_PATH="%(!.%d.%~)"
- spaceleft=`print -Pn "%n@%m $(expand_text $GITBRANCH) $ ls -laCdtrux $(expand_text "$DATE")"`
+ PATHSIZE=$(print -Pn $MY_PATH)
+ PATHSIZE=${#PATHSIZE}
+ spaceleft=`print -Pn "%n@%m $(expand_text "$GITBRANCH") $ ls -laCdtrux -$(expand_text "$DATE")"`
spaceleft=$(($COLUMNS - ${#spaceleft}))
- minimalsize=`print -Pn "%1~"`
- minimalsize=$((3 + ${#minimalsize}))
- [ $spaceleft -lt $minimalsize ] && spaceleft=$minimalsize
+ minimalpathsize=`print -Pn "../%1~"`
+ minimalpathsize=${#minimalpathsize}
+ #minimalgitsize=$((1 + 8)) # ':' + git-abbrev-commit-ish
+ #if [ $spaceleft -lt $(( $PATHSIZE + $GITBRANCHSIZE )) ]
+ #then
+ # reduce the git-branch until it is shrinked to 7 characters max.
+ # if [ $GITBRANCHSIZE -gt 0 ]
+ # then
+ # GITBRANCHSIZE=$(( $spaceleft - $PATHSIZE ))
+ # [ $GITBRANCHSIZE -lt $minimalgitsize ] && GITBRANCHSIZE=$minimalgitsize
+ # GITBRANCH=`print -Pn "%$((GITBRANCHSIZE - 1))>...>$GITBRANCH>>"`
+ # fi
+
+ #fi
+ # then we reduce the path until it reaches the last path element,
+ #spaceleft=$(($spaceleft - $GITBRANCHSIZE))
+ [ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize
CURDIR="$C_$COLOR_PATH$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[reset]$_C"
## Le prompt le plus magnifique du monde, et c'est le mien !