diff options
Diffstat (limited to 'git-prompt.sh')
-rwxr-xr-x | git-prompt.sh | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/git-prompt.sh b/git-prompt.sh index cdc3d05..c908c62 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1,4 +1,3 @@ - # don't set prompt if this is not interactive shell [[ $- != *i* ]] && return @@ -152,7 +151,6 @@ fi #################################################################### MARKERS - screen_marker="sCRn" if [[ $LC_CTYPE =~ "UTF" && $TERM != "linux" ]]; then elipses_marker="…" else @@ -231,7 +229,7 @@ set_shell_label() { screen_label() { # FIXME: run this only if screen is in xterm (how to test for this?) - xterm_label "$screen_marker $plain_who_where $@" + xterm_label "$plain_who_where $@" # FIXME $STY not inherited though "su -" [ "$STY" ] && screen -S $STY -X title "$*" @@ -301,7 +299,11 @@ set_shell_label() { host=${HOSTNAME} if [[ $short_hostname = "on" ]]; then - host=`hostname -s` + if [[ "$(uname)" =~ "CYGWIN" ]]; then + host=`hostname` + else + host=`hostname -s` + fi fi host=${host#$default_host} uphost=`echo ${host} | tr a-z A-Z` @@ -312,7 +314,7 @@ set_shell_label() { host_color=${uphost}_host_color host_color=${!host_color} if [[ -z $host_color && -x /usr/bin/cksum ]] ; then - cksum_color_no=`echo $uphost | cksum | awk '{print $1%7}'` + cksum_color_no=`echo $uphost | cksum | awk '{print $1%6}'` color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256 host_color=${color_index[cksum_color_no]} fi @@ -378,8 +380,7 @@ parse_svn_status() { parse_hg_status() { # ☿ - - [[ -d ./.hg/ ]] || return 1 + hg_root=`hg root 2>/dev/null` || return 1 vcs=hg @@ -397,8 +398,13 @@ parse_hg_status() { branch=`hg branch 2> /dev/null` + [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` + [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && clean=clean vcs_info=${branch/default/D} + if [[ "$bookmark" ]] ; then + vcs_info+=/$bookmark + fi } @@ -423,52 +429,31 @@ parse_git_status() { freshness="$dim" unset branch status modified added clean init added mixed untracked op detached - # quoting hell + # info not in porcelain status eval " $( git status 2>/dev/null | sed -n ' s/^# On branch /branch=/p s/^nothing to commi.*/clean=clean/p s/^# Initial commi.*/init=init/p + s/^# Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p + s/^# Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p + s/^# Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p + ' + )" - s/^# Your branch is ahead of .[/[:alnum:]]\+. by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p - s/^# Your branch is behind .[/[:alnum:]]\+. by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p - s/^# Your branch and .[/[:alnum:]]\+. have diverged.*/freshness=${YELLOW}↕/p - - /^# Changes to be committed:/,/^# [A-Z]/ { - s/^# Changes to be committed:/added=added;/p - - s/^# modified: '"$file_regex"'/ [[ \" ${added_files[*]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\"/p - s/^# new file: '"$file_regex"'/ [[ \" ${added_files[*]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\"/p - s/^# renamed:[^>]*> '"$file_regex"'/ [[ \" ${added_files[*]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\"/p - s/^# copied:[^>]*> '"$file_regex"'/ [[ \" ${added_files[*]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\"/p - } - - /^# Changed but not updated:/,/^# [A-Z]/ { - s/^# Changed but not updated:/modified=modified;/p - s/^# modified: '"$file_regex"'/ [[ \" ${modified_files[*]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\"/p - s/^# unmerged: '"$file_regex"'/ [[ \" ${modified_files[*]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\"/p - } - - /^# Changes not staged for commit:/,/^# [A-Z]/ { - s/^# Changes not staged for commit:/modified=modified;/p - s/^# modified: '"$file_regex"'/ [[ \" ${modified_files[*]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\"/p - s/^# unmerged: '"$file_regex"'/ [[ \" ${modified_files[*]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\"/p - } - - /^# Unmerged paths:/,/^[^#]/ { - s/^# Unmerged paths:/modified=modified;/p - s/^# both modified:\s*'"$file_regex"'/ [[ \" ${modified_files[*]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\"/p - } - - /^# Untracked files:/,/^[^#]/{ - s/^# Untracked files:/untracked=untracked;/p - s/^# '"$file_regex"'/ [[ \" ${untracked_files[*]} ${modified_files[*]} ${added_files[*]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\"/p - } + # porcelain file list + # TODO: sed-less -- http://tldp.org/LDP/abs/html/arrays.html -- Example 27-5 + eval " $( + git status --porcelain 2>/dev/null | + sed -n ' + s/^[MARC]. \(.*\)/ added=added; [[ \" ${added_files[*]} \" =~ \1 ]] || added_files[${#added_files[@]}]=\1/p + s/^.[MAU] \(.*\)/ modified=modified; [[ \" ${modified_files[*]} \" =~ \1 ]] || modified_files[${#modified_files[@]}]=\1/p + s/^?? \(.*\)/ untracked=untracked; [[ \" ${untracked_files[*]} \" =~ \1 ]] || untracked_files[${#untracked_files[@]}]=\1/p ' )" - if ! grep -q "^ref:" $git_dir/HEAD 2>/dev/null; then + if ! grep -q "^ref:" "$git_dir/HEAD" 2>/dev/null; then detached=detached fi |