From 7fb170955946a049a7f2da8d78f49abbf7981d59 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sun, 15 Jun 2008 19:54:33 +0300 Subject: added detached state and corresponding display of branch --- prompt | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index bf492d0..0cc25b1 100755 --- a/prompt +++ b/prompt @@ -30,6 +30,8 @@ git_mixed=yellow # git_untracked=BLUE # # Untracked files: git_op=MAGENTA + git_detached=RED + ##################################################################### post config @@ -84,6 +86,7 @@ git_added=${!git_added} git_op=${!git_op} git_mixed=${!git_mixed} + git_detached=${!git_detached} ##################################################################### LC_ALL=C @@ -307,9 +310,23 @@ PROMPT_COMMAND=' # branch="$(cut -c1-7 "$git_dir/HEAD")..." fi + + ### branch + + #head_tail=`echo $head | sed 's/[^^~]*//'` # we cut head to leave only ^~, and reattach to branch name + branch=${branch/master/M} + + grep -q "^ref:" $git_dir/HEAD 2>/dev/null || detached=detached + [[ -n "$detached" ]] && branch="/dev/null`>" + + head_rev=`git-rev-parse HEAD 2>/dev/null` + head_rev=${head_rev/HEAD/} + head_rev=${head_rev:0:6} + ### sort statuses, choose primary (for branch color) status=${op+op} + status=${status:-$detached} status=${status:-$clean} status=${status:-$modified} status=${status:-$added} @@ -319,21 +336,12 @@ PROMPT_COMMAND=' eval git_color="\${git_$status}" git_color=${git_color:-$WHITE} - ### branch - head=`git-name-rev --name-only HEAD 2>/dev/null` - head_tail=`echo $head | sed 's/[^^~]*//'` # we cut head to leave only ^~, and reattach to branch name - branch=${branch/master/M}$head_tail - - head_rev=`git-rev-parse HEAD 2>/dev/null` - head_rev=${head_rev/HEAD/} - head_rev=${head_rev:0:6} - ### compose local label unset file_list - file_list+="${git_added_files+$git_added$git_added_files }" - file_list+="${git_modified_files+$git_modified$git_modified_files }" - file_list+="${git_untracked_files+$git_untracked$git_untracked_files }" + file_list+="${git_added_files+$git_added$git_added_files}" + file_list+="${git_modified_files+$git_modified$git_modified_files}" + file_list+="${git_untracked_files+$git_untracked$git_untracked_files}" [[ $file_list ]] && file_list=":${file_list}" # ${+ does not works (?) tail_local="(${branch} $white$head_rev$git_color${op+ / $op}$git_color${file_list}$git_color)" @@ -341,7 +349,8 @@ PROMPT_COMMAND=' head_local="${head_local+$git_color $head_local\n}" tail_local="${tail_local+$git_color $tail_local}${dir_color}" - unset branch status git_color clean added modified untracked sep file_list + unset branch status git_color sep file_list + unset clean added modified untracked detached unset git_modified_files unset git_untracked_files unset git_added_files -- cgit v1.2.3