From cfd299e9f22ac4c1ede0317dac69e5ca611c439e Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Wed, 25 Jun 2008 20:39:26 +0300 Subject: fix: wrang state. +cleanup --- demo-script | 7 +++-- prompt | 91 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 48 insertions(+), 50 deletions(-) mode change 100755 => 100644 prompt diff --git a/demo-script b/demo-script index 58e269a..69245e6 100644 --- a/demo-script +++ b/demo-script @@ -1,4 +1,4 @@ -<<<<<<< HEAD:demo-script +set +xv . /t/prompt/prompt test -d demo && rm -rf demo/ test -d ../demo && cd .. && rm -rf demo/ @@ -10,11 +10,11 @@ echo "1st line" > FOO git add FOO touch untracked.o rm untracked.o -git commit -q -m "1st line" FOO +git commit -q -m "FOO's 1st line" git checkout -b test echo "added 2nd line in test" >> FOO git add FOO -echo "2nd FOO" > BAR +echo "1st BAR" > BAR git add BAR echo "added 3nd line" >> FOO git add FOO @@ -31,3 +31,4 @@ git commit -q -m "merged" cat FOO git checkout HEAD^ cat FOO +git checkout master diff --git a/prompt b/prompt old mode 100755 new mode 100644 index 78f9889..0de07c8 --- a/prompt +++ b/prompt @@ -24,14 +24,14 @@ AHP_host_color=white # vcs state colors - init_vcs_color=WHITE # initial - clean_vcs_color=blue # nothing to commit (working directory clean) - modified_vcs_color=red # Changed but not updated: - added_vcs_color=green # Changes to be committed: - mixed_vcs_color=yellow # -untracked_vcs_color=BLUE # Untracked files: - op_vcs_color=MAGENTA - detached_vcs_color=RED + init_vcs_color=WHITE # initial + clean_vcs_color=blue # nothing to commit (working directory clean) + modified_vcs_color=red # Changed but not updated: + added_vcs_color=green # Changes to be committed: + mixed_vcs_color=yellow # + untracked_vcs_color=BLUE # Untracked files: + op_vcs_color=MAGENTA + detached_vcs_color=RED ##################################################################### post config @@ -138,7 +138,7 @@ set_shell_title() { esac } -export -f set_shell_title + export -f set_shell_title ###################################################### ID (user name) id=`id -un` @@ -196,29 +196,29 @@ export -f set_shell_title ########################################################### WHO_WHERE -# who_ware. Is constant. Looks like -# [user@]host[-tty] + # who_ware. Is constant. Looks like + # [user@]host[-tty] -color_who_where="${id:+$id@}$host_color$host${tty:+ $tty}" -plain_who_where="${id:+$id@}$host" + color_who_where="${id:+$id@}$host_color$host${tty:+ $tty}" + plain_who_where="${id:+$id@}$host" -# remove trailing "@" if any -color_who_where="${color_who_where%@}" -plain_who_where="${plain_who_where%@}" + # remove trailing "@" if any + color_who_where="${color_who_where%@}" + plain_who_where="${plain_who_where%@}" -# add traling " " -color_who_where="$color_who_where " -plain_who_where="$plain_who_where " + # add traling " " + color_who_where="$color_who_where " + plain_who_where="$plain_who_where " -# if $who_where==" " then who_where="" -color_who_where="${color_who_where## }" -plain_who_where="${plain_who_where## }" + # if $who_where==" " then who_where="" + color_who_where="${color_who_where## }" + plain_who_where="${plain_who_where## }" -# if root then highlight who_where -if [ "$id" == "root" ] ; then - color_who_where="$root_id_color$color_who_where$colors_reset" -fi + # if root then highlight who_where + if [ "$id" == "root" ] ; then + color_who_where="$root_id_color$color_who_where$colors_reset" + fi parse_svn_dir() { @@ -259,30 +259,26 @@ parse_git_dir() { vcs=git ########################################################## GIT STATUS + unset status modified added clean init added mixed untracked op detached eval ` git status 2>/dev/null | sed -n " s/^# On branch /branch=/p - s/^nothing to commit (working directory clean)/clean=clean/p - s/^# Initial commit/init=init/p - /^# Untracked files:/,/^[^#]/{ s/^# Untracked files:/untracked=untracked/p s/^# /untracked_files+=\" \"/p } - /^# Changed but not updated:/,/^# [A-Z]/ { s/^# Changed but not updated:/modified=modified/p s/^# modified: /modified_files+=\" \"/p s/^# unmerged: /modified_files+=\" \"/p } - /^# Changes to be committed:/,/^# [A-Z]/ { s/^# Changes to be committed:/added=added/p s/^# modified: /added_files+=\" \"/p - s/^# new file: /added_files+=\" \"/p + s/^# new file: */added_files+=\" \"/p s/^# renamed:[^>]*> /added_files+=\" \"/p s/^# copied:[^>]*> /added_files+=\" \"/p } @@ -344,21 +340,23 @@ parse_git_dir() { ### compose vcs_info + if [[ $init ]]; then + vcs_info=init:M - if [[ "$detached" ]] ; then - vcs_info="/dev/null`$white=$rawhex>" - elif [[ "$op" == "merge" ]] ; then - vcs_info="$op: $branch <~ $(git-name-rev --name-only $(<$git_dir/MERGE_HEAD))$white=$rawhex" - - elif [[ "$op" ]]; then - vcs_info="<$op:$branch>" + else + if [[ "$detached" ]] ; then + branch="/dev/null`" - elif [[ $init ]]; then - vcs_info=init - else - vcs_info="${branch}$white=$rawhex" + elif [[ "$op" ]]; then + branch="$op:$branch" + if [[ "$op" == "merge" ]] ; then + branch+="<~$(git-name-rev --name-only $(<$git_dir/MERGE_HEAD))" + fi + branch="<$branch>" + fi + vcs_info="$branch$white=$rawhex" fi } @@ -366,9 +364,8 @@ parse_git_dir() { parse_vcs_dir() { unset file_list modified_files untracked_files added_files - unset vcs vcs_info - unset status modified untracked added + unset status modified untracked added init detached unset file_list modified_files untracked_files added_files parse_git_dir || parse_svn_dir @@ -434,8 +431,8 @@ prompt_command_function() { } -PROMPT_COMMAND=prompt_command_function + PROMPT_COMMAND=prompt_command_function -unset rc id tty bell + unset rc id tty bell # vim: set syntax=sh: -- cgit v1.2.3