From d54e5b487bf1476a4e8cb13a21b8ffd94381593a Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Wed, 3 Oct 2012 00:43:36 -0400 Subject: [PATCH 1/5] Add $head_separator to allow user to put vcs and dir info on separate lines Signed-off-by: Jon Ringle --- git-prompt.conf | 2 ++ git-prompt.sh | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index dee3c0c..41ae28c 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -12,6 +12,8 @@ # max_file_list_length=100 # in characters # count_only=off # off - display file list; on - display file count # rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it) +# head_separator=' ' # separator between vcs info and dir info +## head_separator='\n' # put vcs info and dir info on separate lines ############################################################ MODULES diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..6062f9a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -25,7 +25,7 @@ virtualenv_module=${virtualenv_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} - + head_separator=${head_separator:- } #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 @@ -624,10 +624,10 @@ parse_vcs_status() { fi - head_local="$vcs_color(${vcs_info}$vcs_color${file_list}$vcs_color)" + head_local="$vcs_color(${vcs_info}$vcs_color${file_list}$vcs_color)$head_separator" ### fringes - head_local="${head_local+$vcs_color$head_local }" + head_local="${head_local+$vcs_color$head_local}" #above_local="${head_local+$vcs_color$head_local\n}" #tail_local="${tail_local+$vcs_color $tail_local}${dir_color}" } @@ -704,6 +704,7 @@ prompt_command_function() { # if cwd_cmd have back-slash, then assign it value to cwd # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" + eval "${head_separator/\\/head_separator=\\\\}" PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" From 2b43af401c21ce50815cb1ad3400f6c2bd860b4b Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Wed, 3 Oct 2012 14:48:05 -0400 Subject: [PATCH 2/5] color_who_where: add extra \ escape if $id has \ likewise-open user id's contain a backslash: domain\user The backslash needs to be escaped when colorized Signed-off-by: Jon Ringle --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..58d9d84 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -329,7 +329,7 @@ set_shell_label() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}" + color_who_where="${id//\\/\\\\}${host:+$host_color$at$host}${tty:+ $tty}" plain_who_where="${id}$at$host" # add trailing " " From eb3966e2790fc3a93dc52c5cae269c29e0d6671e Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Thu, 4 Oct 2012 00:17:55 -0400 Subject: [PATCH 3/5] whitespace cleanup Signed-off-by: Jon Ringle --- git-prompt.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index b11bb64..cb3b359 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -25,7 +25,7 @@ virtualenv_module=${virtualenv_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} - head_separator=${head_separator:- } + head_separator=${head_separator:- } #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 @@ -41,9 +41,9 @@ fi unset cols - #### prompt character, for root/non-root - prompt_char=${prompt_char:-'>'} - root_prompt_char=${root_prompt_char:-'>'} + #### prompt character, for root/non-root + prompt_char=${prompt_char:-'>'} + root_prompt_char=${root_prompt_char:-'>'} #### vcs colors init_vcs_color=${init_vcs_color:-WHITE} # initial @@ -422,14 +422,14 @@ parse_git_status() { vcs=git ########################################################## GIT STATUS - added_files=() - modified_files=() - untracked_files=() + added_files=() + modified_files=() + untracked_files=() [[ $rawhex_len -gt 0 ]] && freshness="$dim=" unset branch status modified added clean init added mixed untracked op detached - # info not in porcelain status + # info not in porcelain status eval " $( git status 2>/dev/null | sed -n ' @@ -442,7 +442,7 @@ parse_git_status() { ' )" - # porcelain file list + # porcelain file list # TODO: sed-less -- http://tldp.org/LDP/abs/html/arrays.html -- Example 27-5 # git bug: (was reported to git@vger.kernel.org ) @@ -693,7 +693,7 @@ prompt_command_function() { cwd=${PWD/$HOME/\~} # substitute "~" set_shell_label "${cwd##[/~]*/}/" # default label - path last dir - parse_virtualenv_status + parse_virtualenv_status parse_vcs_status # autojump @@ -704,7 +704,7 @@ prompt_command_function() { # if cwd_cmd have back-slash, then assign it value to cwd # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - eval "${head_separator/\\/head_separator=\\\\}" + eval "${head_separator/\\/head_separator=\\\\}" PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" From d9147b2258e8028c40fafb369a3bcf6287e7c98d Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Thu, 4 Oct 2012 01:03:46 -0400 Subject: [PATCH 4/5] Provide several modes for displaying list of added/mod/untrack files file_list_mode=fileonly Displays just the filename only regardless of which directory a changed file is at. file_list_mode=fullpath Displays the path and filename of changed files file_list_mode=topdir Display just the top level directories if there are changes in that directory or any sub-directory and filenames if they are in the base directory of the repo. This is the behavior that exists before this commit file_list_mode=fulldir Display the full directory name for directories where there are changes and filenames if they are in the base directory of the repo. IMHO, this is a more useful mode. Signed-off-by: Jon Ringle --- git-prompt.conf | 4 ++++ git-prompt.sh | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 41ae28c..40d0f8d 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -14,6 +14,10 @@ # rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it) # head_separator=' ' # separator between vcs info and dir info ## head_separator='\n' # put vcs info and dir info on separate lines +# file_list_mode=topdir # show top directory name of added/modified/untracked files +## file_list_mode=fileonly # show file names of added/modifed/untracked files +## file_list_mode=fulldir # show full directory name of added/modified/untracked files +## file_list_mode=fullpath # show full path to files of added/modified/untracked files ############################################################ MODULES diff --git a/git-prompt.sh b/git-prompt.sh index cb3b359..1dd898c 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -26,6 +26,7 @@ error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} head_separator=${head_separator:- } + file_list_mode=${file_list_mode:-topdir} #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 @@ -407,7 +408,19 @@ parse_hg_status() { fi } +function longdir_or_filename() +{ + local name="${1%${1##*/}}" + [[ "${name:=${1##*/}}" != "/" && name="${name%?}" ]] + echo "$name" +} +function shortdir_or_filename() +{ + local name="${1%${1#*/}}" + [[ "${name:=${1##*/}}" != "/" && name="${name%?}" ]] + echo "$name" +} parse_git_status() { @@ -453,15 +466,33 @@ parse_git_status() { # git status --porcelain # A "with space" <------------- WITH QOUTES + unquoted_match='\([^\"].*\)$' + quoted_match='\"\(.*\)\"$' + + case $file_list_mode in + fileonly) + func_match="\$(basename \"\1\")" + ;; + fullpath) + func_match="\1" + ;; + topdir) + func_match="\$(shortdir_or_filename \"\1\")" + ;; + fulldir|*) + func_match="\$(longdir_or_filename \"\1\")" + ;; + esac + eval " $( git status --porcelain 2>/dev/null | sed -n ' - s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - 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,^.[MAU] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p - s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + s,^[MARC]. '$quoted_match', added=added; [[ \" ${added_files[@]} \" =~ \" '"$func_match"' \" ]] || added_files[${#added_files[@]}]=\"'"$func_match"'\",p + s,^[MARC]. '$unquoted_match', added=added; [[ \" ${added_files[@]} \" =~ \" '"$func_match"' \" ]] || added_files[${#added_files[@]}]=\"'"$func_match"'\",p + s,^.[MAU] '$quoted_match', modified=modified; [[ \" ${modified_files[@]} \" =~ \" '"$func_match"' \" ]] || modified_files[${#modified_files[@]}]=\"'"$func_match"'\",p + s,^.[MAU] '$unquoted_match', modified=modified; [[ \" ${modified_files[@]} \" =~ \" '"$func_match"' \" ]] || modified_files[${#modified_files[@]}]=\"'"$func_match"'\",p + s,^?? '$quoted_match', untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" '"$func_match"' \" ]] || untracked_files[${#untracked_files[@]}]=\"'"$func_match"'\",p + s,^?? '$unquoted_match', untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" '"$func_match"' \" ]] || untracked_files[${#untracked_files[@]}]=\"'"$func_match"'\",p ' # |tee /dev/tty )" From d68379120abbcad55e2c849410c6f1c0ef4e2b48 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Thu, 4 Oct 2012 01:05:31 -0400 Subject: [PATCH 5/5] Allow git per-repo configuration overrides You can override on a git per-repo by creating a .git/.git-prompt.conf NOTE: If you do this, prefix any variable overrides with 'local' i.e.: local file_list_mode=fileonly Signed-off-by: Jon Ringle --- git-prompt.conf | 7 ++++++- git-prompt.sh | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index 40d0f8d..c7fc1d9 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -5,7 +5,12 @@ ### lines commented-out with double '##' are examples ### ### NOTE: this is bash syntax - no spaces around "=" - +### +### You can override on a git per-repo by creating a .git/.git-prompt.conf +### NOTE: If you do this, prefix any variable overrides with 'local' +### i.e.: +### local file_list_mode=fileonly +### ########################################################### # error_bell=off # sound terminal bell when command return code is not zero. (use setterm to set pitch and duration) diff --git a/git-prompt.sh b/git-prompt.sh index 1dd898c..8088aee 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -432,6 +432,11 @@ parse_git_status() { [[ -n ${git_dir/./} ]] || return 1 + # Allow per-repo configuration overrides + conf=${git_dir}/.git-prompt.conf; + [[ -r $conf ]] && . $conf + unset conf + vcs=git ########################################################## GIT STATUS