From 2c24aa69ffbecae6c4eb8f541c6f3da345241462 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 2 Mar 2012 11:49:03 +0100 Subject: [Prompts] Hurrah !! Git-rebases are managed better than ever, with squishable git-hash :) --- 01_Internal.zsh | 6 ++++-- 12_Prompts.zsh | 51 ++++++++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/01_Internal.zsh b/01_Internal.zsh index e8a27c8..f11a2bc 100644 --- a/01_Internal.zsh +++ b/01_Internal.zsh @@ -118,6 +118,8 @@ __get_hg_branch () fi } +__cleanup_git_branch_name() { sed 's,^tags/,,;s,^remotes/,,;s,\^0$,,' } + __get_git_branch () { local my_git_branch checkouted_branch="yes" @@ -145,7 +147,7 @@ __get_git_branch () # If not on a working GIT branch, get the named current commit-ish inside parenthesis [ "$my_git_branch" = "(no branch)" ] &&\ checkouted_branch="" && \ - my_git_branch="$(git name-rev --name-only HEAD 2>&- | sed 's,^tags/,,;s,^remotes/,,;s,\^0$,,')" + my_git_branch="$(git name-rev --name-only HEAD 2>&- | __cleanup_git_branch_name)" # If neither on a named commit-ish, show commit-id if [ "$my_git_branch" = "undefined" ] @@ -186,7 +188,7 @@ __get_git_branch () fi # Then the result - my_git_branch="[rebase $current/$last: "$(git name-rev --name-only "$(cat $REBASE_DIR/onto 2>/dev/null)" 2>/dev/null)".."$my_git_branch"]" + my_git_branch="[$current/$last: "$(git name-rev --name-only "$(cat $REBASE_DIR/onto 2>/dev/null)" 2>/dev/null | __cleanup_git_branch_name)".."$(echo $my_git_branch)"]" [ -r $REBASE_DIR/head-name ] && my_git_branch=$my_git_branch" "$(< $REBASE_DIR/head-name sed 's/^refs\///;s/^heads\///') else # No rebase in progress, put '(' ')' if needed diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 3664b2b..4157d03 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -295,29 +295,34 @@ __update_prompt_elements() then if [ $spaceleft -lt $(( $PATHSIZE + $GITBRANCHSIZE )) ] then - local unbreakablegittail - if [ "$(echo $GITBRANCH | grep "^\[rebase ")" = "" ] - then - # reduce the git-branch until it is shrinked to $minimalgitsize characters max. - - if [ $GITBRANCH[-1] = ")" ] - then - unbreakablegittail=${${(M)GITBRANCH%\~*}} - [ "$unbreakablegittail" = "" -a $GITBRANCHSIZE -gt $minimalgitsize ] && unbreakablegittail=")" - fi - if [ $GITBRANCHSIZE -gt $minimalgitsize ] - then - GITBRANCHSIZE=$(( $spaceleft - $PATHSIZE )) - [ $GITBRANCHSIZE -lt $minimalgitsize ] && GITBRANCHSIZE=$minimalgitsize - fi - GITBRANCH=`print -Pn "%"$(($GITBRANCHSIZE - ${#unbreakablegittail}))">..>"${GITBRANCH%\~*}${unbreakablegittail:+"%"${#unbreakablegittail}"<<"$GITBRANCH}` - else - - # - # TODO : réduire la taille du hash, s'il y en a un. - # - - fi + local unbreakablegittail rebasing + + if [ "$(echo $GITBRANCH | grep "^ \[")" != "" ] + then + # + # TODO : réduire la taille du hash, s'il y en a un. + # + rebasing=$GITBRANCH + GITBRANCH=${${GITBRANCH/*../}/] */} + fi + + # reduce the git-branch until it is shrinked to $minimalgitsize characters max. + if [ $GITBRANCH[-1] = ")" ] + then + unbreakablegittail=${${(M)GITBRANCH%\~*}} + [ "$unbreakablegittail" = "" -a $GITBRANCHSIZE -gt $minimalgitsize ] && unbreakablegittail=$GITBRANCH[-1] + fi + if [ $GITBRANCHSIZE -gt $minimalgitsize ] + then + GITBRANCHCHUNK=$(( $GITBRANCHSIZE - ($spaceleft - $PATHSIZE) )) + [ $((${#GITBRANCH} - $GITBRANCHCHUNK)) -lt $minimalgitsize ] && GITBRANCHCHUNK=$((${#GITBRANCH} - $minimalgitsize)) + fi + GITBRANCH=`print -Pn "%"$(( (${#GITBRANCH} - $GITBRANCHCHUNK) - ${#unbreakablegittail}))">¬>"${GITBRANCH%\~*}${unbreakablegittail:+"%"${#unbreakablegittail}"<<"$GITBRANCH}` + + if [ -n "$rebasing" ] + then + GITBRANCH=${rebasing/..*]/..$GITBRANCH]} + fi fi fi # then we reduce the path until it reaches the last path element, -- cgit v1.2.3