From f4982398816e2dee92e0f7483b0c2c3456c3ec8d Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 2 Mar 2012 12:36:52 +0100 Subject: [Prompts] Woaw.. Et voilà ! Now it colorizes only the *EFFECTIVE* git hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01_Internal.zsh | 8 ++------ 12_Prompts.zsh | 44 +++++++++++++++----------------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/01_Internal.zsh b/01_Internal.zsh index f11a2bc..b8bec64 100644 --- a/01_Internal.zsh +++ b/01_Internal.zsh @@ -164,6 +164,8 @@ __get_git_branch () fi fi + my_git_branch="→"$my_git_branch"←" + # Rebase in progress ? if [ -d $GIT_DIR/rebase-merge -o -d $GIT_DIR/rebase-apply ] then @@ -187,7 +189,6 @@ __get_git_branch () last=$(cat $REBASE_DIR/last) fi - # Then the result 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 @@ -195,11 +196,6 @@ __get_git_branch () [ ! "$checkouted_branch" ] && my_git_branch="($my_git_branch)" fi - if [ "$(git status 2>&- | grep "new file" | head -n1)" != "" ] ; then - # ADDED FILES - my_git_branch=$my_git_branch - fi - echo " "$my_git_branch } diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 4157d03..628c060 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -295,40 +295,26 @@ __update_prompt_elements() then if [ $spaceleft -lt $(( $PATHSIZE + $GITBRANCHSIZE )) ] then - 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 + CHUNKABLE=${${GITBRANCH/*→/}/←*/} + + # reduce the git-branch until it is shrinked to $minimalgitsize characters max. + if [ $GITBRANCHSIZE -gt $minimalgitsize ] + then + GITBRANCHCHUNK=$(( $GITBRANCHSIZE - ($spaceleft - $PATHSIZE) )) + [ $((${#CHUNKABLE} - $GITBRANCHCHUNK)) -lt $minimalgitsize ] && GITBRANCHCHUNK=$((${#CHUNKABLE} - $minimalgitsize)) + fi + CHUNKABLE=`print -Pn "%"$(( ${#CHUNKABLE} - $GITBRANCHCHUNK ))">¬>"${CHUNKABLE%\~*}` + + GITBRANCH=${GITBRANCH/→*←/→$CHUNKABLE←} fi fi # then we reduce the path until it reaches the last path element, spaceleft=$(($spaceleft - $GITBRANCHSIZE)) [ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize - GITBRANCH=${GITBRANCH:+$C_"$(__get_git_status)"$_C$GITBRANCH}"$(__get_guilt_series)$C_$color[none]$_C" + if [ -n "$GITBRANCH" ] + then + GITBRANCH=$C_$_prompt_colors[soft_generic]$_C${${GITBRANCH/→/$C_"$(__get_git_status)"$_C}/←/$C_$_prompt_colors[soft_generic]$_C}"$(__get_guilt_series)$C_$color[none]$_C" + fi CURDIR="$C_$_prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" [ "$DEBUG" = "yes" ] && echo } -- cgit v1.2.3