From d054b3a9a39395ce1cf49233f0b90c9dad041703 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 26 Aug 2015 10:44:33 +0200 Subject: [PATCH 01/69] Added Gitter, removed Gittip --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9be4440..75663eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Informative git prompt for bash and fish +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/magicmonty/bash-git-prompt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + This prompt is a port of the "Informative git prompt for zsh" which you can find [here](https://github.com/olivierverdier/zsh-git-prompt) @@ -302,9 +304,8 @@ Please leave a comment on the issue, that you want to fix it, so others know, th Pull requests are welcome. I will check them and merge them, if I think they help the project. ## Donations -I accept tips through [Gittip][tip] and [Flattr][flattr]. +I accept tips through [Flattr][flattr]. -[![Gittip](https://img.shields.io/gittip/magicmonty.svg?style=flat)](https://www.gittip.com/magicmonty/) [![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt) [blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ From 90f1cd2f010ba65c6da03f35f69fb31161d8e3bf Mon Sep 17 00:00:00 2001 From: Chandrasing Date: Mon, 7 Sep 2015 13:02:37 +0530 Subject: [PATCH 02/69] [Local Branch Indicator] Change case from No upstream to no upstream This commit fixes the Local Indicator which was broken because of theme related changes. --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 68d1a08..c9b72c2 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -78,7 +78,7 @@ else # detect if the local branch have a remote tracking branch cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) - if [ `count_lines "$cmd_output" "fatal: No upstream"` == 1 ] ; then + if [ `count_lines "$cmd_output" "fatal: no upstream"` == 1 ] ; then has_remote_tracking=0 else has_remote_tracking=1 From 01f83ee94a48362c9b2db1cb3018f36c50ad2fe1 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Mon, 7 Sep 2015 22:54:48 +0200 Subject: [PATCH 03/69] Adds new theme by @chmike. Fixes #152 --- themes/Chmike.bgptheme | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 themes/Chmike.bgptheme diff --git a/themes/Chmike.bgptheme b/themes/Chmike.bgptheme new file mode 100644 index 0000000..33f9655 --- /dev/null +++ b/themes/Chmike.bgptheme @@ -0,0 +1,31 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# it is clone of oh-my-zsh crunch theme style with exit status + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M)" + + + GIT_PROMPT_THEME_NAME="Chmike" + GIT_PROMPT_BRANCH="${Green}" + GIT_PROMPT_REMOTE=" " + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="⭐" + + GIT_PROMPT_SEPARATOR="|" + GIT_PROMPT_CHANGED="${Cyan}❗" + GIT_PROMPT_STAGED="${Yellow}▸" + GIT_PROMPT_UNTRACKED="${Blue}…" + GIT_PROMPT_CONFLICTS="${BoldRed}❓" + GIT_PROMPT_STASHED="${Magenta}>" + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" +} + +reload_git_prompt_colors "Crunch" From 8a04c7c260ee9c87edb4a4f4c6fb233641b825b5 Mon Sep 17 00:00:00 2001 From: oGre Date: Thu, 10 Sep 2015 21:05:55 +0200 Subject: [PATCH 04/69] Fixed typo in echoed text --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 323fcfc..4506ce1 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -117,7 +117,7 @@ function git_prompt_make_custom_theme() { if [[ "${base}" = "Custom" ]]; then echoc ${Red} "You cannot use the custom theme as base" else - echoc ${Green} "Creating new cutom theme in \"${HOME}/.git-prompt-colors.sh\"" + echoc ${Green} "Creating new custom theme in \"${HOME}/.git-prompt-colors.sh\"" echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" if [[ "${base}" == "Default" ]]; then cp "${__GIT_PROMPT_DIR}/themes/Custom.bgptemplate" "${HOME}/.git-prompt-colors.sh" From 31f690f65cef62ac6be960c3b6c32337a218bad0 Mon Sep 17 00:00:00 2001 From: oGre Date: Thu, 10 Sep 2015 21:59:29 +0200 Subject: [PATCH 05/69] Check if prompt_callback is a function must occur after theme has loaded if theme is to override prompt_callback --- gitprompt.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 323fcfc..6056eb5 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -225,6 +225,12 @@ function git_prompt_config() git_prompt_load_theme + if [ "`type -t prompt_callback`" = 'function' ]; then + prompt_callback="prompt_callback" + else + prompt_callback="prompt_callback_default" + fi + if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; else @@ -523,12 +529,6 @@ function prompt_callback_default { } function gp_install_prompt { - if [ "`type -t prompt_callback`" = 'function' ]; then - prompt_callback="prompt_callback" - else - prompt_callback="prompt_callback_default" - fi - if [ -z "$OLD_GITPROMPT" ]; then OLD_GITPROMPT=$PS1 fi From b3194732a0805c16a760e85eaa224a54ae5657af Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 11 Sep 2015 09:43:33 +0200 Subject: [PATCH 06/69] Custom theme using prompt_callback --- themes/TruncatedPwd_WindowTitle.bgptheme | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 themes/TruncatedPwd_WindowTitle.bgptheme diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme new file mode 100644 index 0000000..3ab9a75 --- /dev/null +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -0,0 +1,54 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=Default_TruncatedPwd_WindowTitle +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + + #Sets the window title to the given argument string + function gp_set_title { + echo -ne "\033]0;"$@"\007" + } + + #Helper function that truncates $PWD depending on window width + function gp_truncate_pwd { + local newPWD="${PWD/#$HOME/~}" + local pwdmaxlen=$((${COLUMNS:-80}/3)) + [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" + echo -n "$newPWD" + } + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_title $PS1 + echo -n "[${PS1}]${ResetColor}" + } + + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_START_USER="${Yellow}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle" From bc806a254a6c57c47aba20f72b283e4279d0889b Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 11 Sep 2015 10:17:25 +0200 Subject: [PATCH 07/69] Fixed documentation --- themes/TruncatedPwd_WindowTitle.bgptheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 3ab9a75..734600c 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -14,7 +14,7 @@ # # Example usage: # if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then -# GIT_PROMPT_THEME=Default_TruncatedPwd_WindowTitle +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle # source ~/.bash-git-prompt/gitprompt.sh # fi # From 554f14bf235ab7ce10392ffd4ec3e1513143037d Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 11 Sep 2015 14:00:09 +0200 Subject: [PATCH 08/69] Re-indented functions. Added unset of prompt_callback when calling reset prompt. Call reset prompt when loading new theme. Added quicker check for function type. --- gitprompt.sh | 97 +++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 98c7696..ed60902 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -1,14 +1,13 @@ #!/bin/sh -function async_run() +function async_run() { { eval "$@" &> /dev/null }& } -function git_prompt_dir() -{ +function git_prompt_dir() { # assume the gitstatus.sh is in the same directory as this script # code thanks to http://stackoverflow.com/questions/59895 if [ -z "$__GIT_PROMPT_DIR" ]; then @@ -23,11 +22,10 @@ function git_prompt_dir() } function echoc() { - echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' + echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' } -function get_theme() -{ +function get_theme() { local CUSTOM_THEME_FILE="${HOME}/.git-prompt-colors.sh" local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" @@ -67,16 +65,15 @@ function get_theme() fi } -function git_prompt_load_theme() -{ +function git_prompt_load_theme() { + git_prompt_reset get_theme local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" source "${DEFAULT_THEME_FILE}" source "${__GIT_PROMPT_THEME_FILE}" } -function git_prompt_list_themes() -{ +function git_prompt_list_themes() { local oldTheme local oldThemeFile @@ -160,7 +157,7 @@ function gp_set_file_var() { # return 0 (true) if any FILEPATH is readable, set ENVAR to it # return 1 (false) if not -function gp_maybe_set_envar_to_path(){ +function gp_maybe_set_envar_to_path() { local envar="$1" shift local file @@ -183,6 +180,7 @@ git_prompt_reset() { for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD GIT_PROMPT_THEME_NAME; do unset $var done + unset -f prompt_callback } # gp_format_exit_status RETVAL @@ -203,8 +201,7 @@ gp_format_exit_status() { fi } -function git_prompt_config() -{ +function git_prompt_config() { #Checking if root to change output _isroot=false [[ $UID -eq 0 ]] && _isroot=true @@ -225,10 +222,10 @@ function git_prompt_config() git_prompt_load_theme - if [ "`type -t prompt_callback`" = 'function' ]; then - prompt_callback="prompt_callback" + if is_function prompt_callback; then + prompt_callback="prompt_callback" else - prompt_callback="prompt_callback_default" + prompt_callback="prompt_callback_default" fi if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then @@ -369,42 +366,42 @@ function setGitPrompt() { _have_find_mmin=1 function olderThanMinutes() { - local matches - local find_exit_code - - if [[ -z "$_find_command" ]]; then - if command -v gfind > /dev/null; then - _find_command=gfind - else - _find_command=find - fi - fi + local matches + local find_exit_code - if [[ "$_have_find_mmin" = 1 ]]; then - matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` - find_exit_code="$?" - if [[ -n "$matches" ]]; then - return 0 - else - if [[ "$find_exit_code" != 0 ]]; then - _have_find_mmin=0 - else - return 1 - fi - fi + if [[ -z "$_find_command" ]]; then + if command -v gfind > /dev/null; then + _find_command=gfind + else + _find_command=find fi + fi - # try perl, solaris ships with perl - if command -v perl > /dev/null; then - perl -e '((time - (stat("'"$1"'"))[9]) / 60) > '"$2"' && exit(0) || exit(1)' - return "$?" + if [[ "$_have_find_mmin" = 1 ]]; then + matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` + find_exit_code="$?" + if [[ -n "$matches" ]]; then + return 0 else - echo >&2 - echo "WARNING: neither a find that supports -mmin (such as GNU find) or perl is available, disabling remote status checking. Install GNU find as gfind or perl to enable this feature, or set GIT_PROMPT_FETCH_REMOTE_STATUS=0 to disable this warning." >&2 - echo >&2 - GIT_PROMPT_FETCH_REMOTE_STATUS=0 + if [[ "$find_exit_code" != 0 ]]; then + _have_find_mmin=0 + else return 1 + fi fi + fi + + # try perl, solaris ships with perl + if command -v perl > /dev/null; then + perl -e '((time - (stat("'"$1"'"))[9]) / 60) > '"$2"' && exit(0) || exit(1)' + return "$?" + else + echo >&2 + echo "WARNING: neither a find that supports -mmin (such as GNU find) or perl is available, disabling remote status checking. Install GNU find as gfind or perl to enable this feature, or set GIT_PROMPT_FETCH_REMOTE_STATUS=0 to disable this warning." >&2 + echo >&2 + GIT_PROMPT_FETCH_REMOTE_STATUS=0 + return 1 + fi } function checkUpstream() { @@ -524,8 +521,14 @@ function updatePrompt() { PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" } +# Use exit status from declare command to determine whether input argument is a +# bash function +function is_function { + declare -Ff "$1" >/dev/null; +} + function prompt_callback_default { - return + return } function gp_install_prompt { From ffe831d659c0c61ba8a797640e99b3fb8bb00bd1 Mon Sep 17 00:00:00 2001 From: oGre Date: Sat, 12 Sep 2015 17:48:43 +0200 Subject: [PATCH 09/69] Missed two functions --- gitprompt.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index ed60902..e02fb68 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -1,7 +1,6 @@ #!/bin/sh -function async_run() -{ +function async_run() { { eval "$@" &> /dev/null }& @@ -421,8 +420,7 @@ function checkUpstream() { fi } -function replaceSymbols() -{ +function replaceSymbols() { if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L fi From df40c38f265388f1be0913d22fd744a51e648551 Mon Sep 17 00:00:00 2001 From: oGre Date: Sat, 12 Sep 2015 21:08:15 +0200 Subject: [PATCH 10/69] re-indented replaceSymbols function containing tab stops --- gitprompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index e02fb68..97b12d0 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -425,11 +425,11 @@ function replaceSymbols() { GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L fi - local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} - local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} - echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } function updatePrompt() { From abcc68b2f72081b435afac82ce5760d416ac7b87 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 15 Sep 2015 16:21:47 +0200 Subject: [PATCH 11/69] Added NoExitState version of my TruncatedPwd theme --- ...ncatedPwd_WindowTitle_NoExitState.bgptheme | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme new file mode 100644 index 0000000..09f1ba9 --- /dev/null +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -0,0 +1,54 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + + #Sets the window title to the given argument string + function gp_set_title { + echo -ne "\033]0;"$@"\007" + } + + #Helper function that truncates $PWD depending on window width + function gp_truncate_pwd { + local newPWD="${PWD/#$HOME/~}" + local pwdmaxlen=$((${COLUMNS:-80}/3)) + [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" + echo -n "$newPWD" + } + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_title $PS1 + echo -n "[${PS1}]${ResetColor}" + } + + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_START_USER="${Yellow}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT="\n${White}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle" From 168d33c3ab5ae0ad794e0771d1c6376b12360518 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 15 Sep 2015 16:24:43 +0200 Subject: [PATCH 12/69] Fixed name everywhere and documentation --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 09f1ba9..f0bb330 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -6,7 +6,7 @@ # # The prompt will use a Debian-style on the form # -# [user@host: ] [bash-git-prompt-info] +# [user@host: ] [bash-git-prompt-info] # HH:MM $ # # The window title will have the form @@ -14,14 +14,14 @@ # # Example usage: # if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then -# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle_NoExitState # source ~/.bash-git-prompt/gitprompt.sh # fi # # oGre [https://github.com/ogr3] ############################################################################## override_git_prompt_colors() { - GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" #Sets the window title to the given argument string function gp_set_title { @@ -51,4 +51,4 @@ override_git_prompt_colors() { GIT_PROMPT_END_ROOT="\n${White}${Time12a}${ResetColor} # " } -reload_git_prompt_colors "TruncatedPwd_WindowTitle" +reload_git_prompt_colors "TruncatedPwd_WindowTitle_NoExitState" From 6d67d0c3d9e8d2d7dc440d793e33a9018099f109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denny=20Sch=C3=A4fer?= Date: Tue, 15 Sep 2015 22:11:33 +0200 Subject: [PATCH 13/69] Remove trailing whitespaces in the TruncatedPwd_WindowTitle theme --- themes/TruncatedPwd_WindowTitle.bgptheme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 734600c..3c2c4cc 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -1,13 +1,13 @@ ############################################################################## # Changes the prompt to a Debian-style one that truncates pwd to a max length -# depending on the terminal column width. Also uses the prompt_callback -# function of bash-git-prompt to set the window title to almost the same +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same # Debian-style. # # The prompt will use a Debian-style on the form # # [user@host: ] [bash-git-prompt-info] -# HH:MM $ +# HH:MM $ # # The window title will have the form # user@host: @@ -44,7 +44,7 @@ override_git_prompt_colors() { } Time12a="\$(date +%H:%M)" - + GIT_PROMPT_START_USER="${Yellow}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor} $ " From ee959b7e5921d969f1613c6889c5bbb39a1aae50 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 16 Sep 2015 06:20:02 +0200 Subject: [PATCH 14/69] Remove training whitespace --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index f0bb330..fdd0f50 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -1,13 +1,13 @@ ############################################################################## # Changes the prompt to a Debian-style one that truncates pwd to a max length -# depending on the terminal column width. Also uses the prompt_callback -# function of bash-git-prompt to set the window title to almost the same +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same # Debian-style. # # The prompt will use a Debian-style on the form # -# [user@host: ] [bash-git-prompt-info] -# HH:MM $ +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ # # The window title will have the form # user@host: @@ -44,7 +44,7 @@ override_git_prompt_colors() { } Time12a="\$(date +%H:%M)" - + GIT_PROMPT_START_USER="${Yellow}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER="\n${White}${Time12a}${ResetColor} $ " From 4a993d873546e4f86b9d03bf7e8580bc973c34ed Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 18 Sep 2015 16:28:29 +0200 Subject: [PATCH 15/69] Makes merge conflicts clearer fixes #151 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75663eb..09a24f9 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ The symbols are as follows: - Local Status Symbols - ``✔``: repository clean - ``●n``: there are ``n`` staged files - - ``✖n``: there are ``n`` unmerged files + - ``✖n``: there are ``n`` files with merge conflict(s) - ``✚n``: there are ``n`` changed but *unstaged* files - ``…n``: there are ``n`` untracked files - ``⚑n``: there are ``n`` stash entries From b46a233a055b114fa92add71368396b5d95723b7 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 18 Sep 2015 16:29:14 +0200 Subject: [PATCH 16/69] Update git-prompt-help.sh relates to #151 --- git-prompt-help.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index 40e98cd..d15db0e 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -22,7 +22,7 @@ LOCALSTATUS is one of the following: ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files - ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files + ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N files with merge conflicts ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries From 54162e71d0f696dd2a977fda0ee625d08c83e792 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Sun, 20 Sep 2015 11:41:45 -0500 Subject: [PATCH 17/69] Use `git status --porcelain --branch` to improve performance Based off of changes by @wkentaro to zsh-git-prompt see: https://github.com/olivierverdier/zsh-git-prompt/pull/65 --- gitstatus.py | 174 ++++++++++++++++++++++++++++----------------------- gitstatus.sh | 89 +++++++++----------------- 2 files changed, 126 insertions(+), 137 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index f350409..423619a 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -32,93 +32,109 @@ except SyntaxError: w(str(a)) w(kwd.get("end", "\n")) - # change those symbols to whatever you prefer symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'} -from subprocess import Popen, PIPE - import sys -gitsym = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE) -branch, error = gitsym.communicate() - -error_string = error.decode('utf-8') - -if 'fatal: Not a git repository' in error_string: - sys.exit(0) - -branch = branch.decode('utf-8').strip()[11:] - -res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate() -err_string = err.decode('utf-8') - -if 'fatal' in err_string: - sys.exit(0) - -changed_files = [namestat[0] for namestat in res.splitlines()] -staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()] -nb_changed = len(changed_files) - changed_files.count('U') -nb_U = staged_files.count('U') -nb_staged = len(staged_files) - nb_U -staged = str(nb_staged) -conflicts = str(nb_U) -changed = str(nb_changed) -status_lines = Popen(['git','status','-s','-uall'],stdout=PIPE).communicate()[0].splitlines() -untracked_lines = [a for a in map(lambda s: s.decode('utf-8'), status_lines) if a.startswith("??")] -nb_untracked = len(untracked_lines) -untracked = str(nb_untracked) -stashes = Popen(['git','stash','list'],stdout=PIPE).communicate()[0].splitlines() -nb_stashed = len(stashes) -stashed = str(nb_stashed) - -if not nb_changed and not nb_staged and not nb_U and not nb_untracked and not nb_stashed: - clean = '1' -else: - clean = '0' - +import re +import shlex +from subprocess import Popen, PIPE, check_output + + +def get_tagname_or_hash(): + """return tagname if exists else hash""" + cmd = 'git log -1 --format="%h%d"' + output = check_output(shlex.split(cmd)).decode('utf-8').strip() + hash_, tagname = None, None + # get hash + m = re.search('\(.*\)$', output) + if m: + hash_ = output[:m.start()-1] + # get tagname + m = re.search('tag: .*[,\)]', output) + if m: + tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1] + + if tagname: + return tagname + elif hash_: + return hash_ + return None + +def get_stash(): + cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + stashFile = '%s%s' % (so.decode('utf-8').rstrip(),'/logs/refs/stash') + + try: + with open(stashFile) as f: + return sum(1 for _ in f) + except IOError: + return 0 + +# `git status --porcelain --branch` can collect all information +# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind +po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE) +stdout, sterr = po.communicate() +if po.returncode != 0: + sys.exit(0) # Not a git repository + +# collect git status information +untracked, staged, changed, conflicts = [], [], [], [] +ahead, behind = 0, 0 remote = '' - -tag, tag_error = Popen(['git', 'describe', '--exact-match'], stdout=PIPE, stderr=PIPE).communicate() - -if not branch: # not on any branch - if tag: # if we are on a tag, print the tag's name - branch = tag - else: - branch = symbols['prehash']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0].decode('utf-8')[:-1] +status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()] +for st in status: + if st[0] == '#' and st[1] == '#': + if re.search('Initial commit on', st[2]): + branch = st[2].split(' ')[-1] + elif re.search('no branch', st[2]): # detached status + branch = get_tagname_or_hash() + elif len(st[2].strip().split('...')) == 1: + branch = st[2].strip() + else: + # current and remote branch info + branch, rest = st[2].strip().split('...') + if len(rest.split(' ')) == 1: + # remote_branch = rest.split(' ')[0] + pass + else: + # ahead or behind + divergence = ' '.join(rest.split(' ')[1:]) + divergence = divergence.lstrip('[').rstrip(']') + for div in divergence.split(', '): + if 'ahead' in div: + ahead = int(div[len('ahead '):].strip()) + remote += '%s%s' % (symbols['ahead of'], ahead) + elif 'behind' in div: + behind = int(div[len('behind '):].strip()) + remote += '%s%s' % (symbols['behind'], behind) + elif st[0] == '?' and st[1] == '?': + untracked.append(st) + else: + if st[1] == 'M': + changed.append(st) + if st[0] == 'U': + conflicts.append(st) + elif st[0] != ' ': + staged.append(st) + +if not changed and not staged and not conflicts and not untracked: + clean = 1 else: - remote_name = Popen(['git','config','branch.%s.remote' % branch], stdout=PIPE).communicate()[0].strip() - if remote_name: - merge_name = Popen(['git','config','branch.%s.merge' % branch], stdout=PIPE).communicate()[0].strip() - else: - remote_name = "origin" - merge_name = "refs/heads/%s" % branch - - if remote_name == '.': # local - remote_ref = merge_name - else: - remote_ref = 'refs/remotes/%s/%s' % (remote_name, merge_name[11:]) - revgit = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % remote_ref],stdout=PIPE, stderr=PIPE) - revlist = revgit.communicate()[0] - if revgit.poll(): # fallback to local - revlist = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % merge_name],stdout=PIPE, stderr=PIPE).communicate()[0] - behead = revlist.splitlines() - ahead = len([x for x in behead if x[0]=='>']) - behind = len(behead) - ahead - if behind: - remote += '%s%s' % (symbols['behind'], behind) - if ahead: - remote += '%s%s' % (symbols['ahead of'], ahead) + clean = 0 if remote == "": - remote = '.' + remote = '.' out = '\n'.join([ - str(branch), - str(remote), - staged, - conflicts, - changed, - untracked, - stashed, - clean]) + branch, + remote.decode('utf-8'), + str(len(staged)), + str(len(conflicts)), + str(len(changed)), + str(len(untracked)), + str(get_stash()), + str(clean) +]) Print(out) diff --git a/gitstatus.sh b/gitstatus.sh index c9b72c2..59f3673 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -6,8 +6,7 @@ # Alan K. Stebbens [http://github.com/aks] # helper functions -count_lines() { echo "$1" | egrep -c "^$2" ; } -all_lines() { echo "$1" | grep -v "^$" | wc -l ; } +count_lines() { echo "$1" | egrep -c $3 "^$2" ; } if [ -z "${__GIT_PROMPT_DIR}" ]; then SOURCE="${BASH_SOURCE[0]}" @@ -19,39 +18,38 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -gitsym=`git symbolic-ref HEAD` +gitstatus=`git status --porcelain --branch` -# if "fatal: Not a git repo .., then exit -case "$gitsym" in fatal*) exit 0 ;; esac +# if the status is fatal, exit now +[[ "$?" -ne 0 ]] && exit 0 -# the current branch is the tail end of the symbolic reference -branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" +num_staged=`count_lines "$gitstatus" "(\?\?|##| )" "-v"` +num_changed=`count_lines "$gitstatus" ".M"` +num_conflicts=`count_lines "$gitstatus" "U"` +num_untracked=`count_lines "$gitstatus" "\?\?"` -gitstatus=`git diff --name-status 2>&1` - -# if the diff is fatal, exit now -case "$gitstatus" in fatal*) exit 0 ;; esac - - -staged_files=`git diff --staged --name-status` - -num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) -num_conflicts=`count_lines "$staged_files" U` -num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 -else - num_stashed=`git stash list | wc -l` +else + stash_file="`git rev-parse --git-dir`/logs/refs/stash" + if [[ -e "${stash_file}" ]]; then + num_stashed=`wc -l "${stash_file}" | cut -d' ' -f 1` + else + num_stashed=0 + fi fi clean=0 -if (( num_changed == 0 && num_staged == 0 && num_U == 0 && num_untracked == 0 && num_stashed == 0 )) ; then +if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed == 0 )) ; then clean=1 fi remote= +branch_line=`echo $gitstatus | grep "^##"` +IFS="." read -ra line <<< "${branch_line/\#\# }" +branch="${line[0]}" + if [[ -z "$branch" ]]; then tag=`git describe --exact-match` if [[ -n "$tag" ]]; then @@ -59,52 +57,27 @@ if [[ -z "$branch" ]]; then else branch="_PREHASH_`git rev-parse --short HEAD`" fi +elif [[ "$branch" == *"Initial commit on"* ]]; then + IFS=" " read -ra branch_line <<< "$branch" + branch=${branch_line[-1]} +elif [[ "$branch" == *"no branch"* ]]; then + branch="_PREHASH_`git rev-parse --short HEAD`" else - remote_name=`git config branch.${branch}.remote` - - if [[ -n "$remote_name" ]]; then - merge_name=`git config branch.${branch}.merge` - else - remote_name='origin' - merge_name="refs/heads/${branch}" - fi - - if [[ "$remote_name" == '.' ]]; then - remote_ref="$merge_name" - else - remote_ref="refs/remotes/$remote_name/${merge_name##refs/heads/}" - fi - - # detect if the local branch have a remote tracking branch - cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) - - if [ `count_lines "$cmd_output" "fatal: no upstream"` == 1 ] ; then - has_remote_tracking=0 - else - has_remote_tracking=1 + IFS="[]" read -ra remote_line <<< "${line[3]}" + if [[ "${remote_line[1]}" == *ahead* ]]; then + num_ahead=`echo "${remote_line[1]}" | cut -c 7-` + remote="${remote}_AHEAD_${num_ahead}" fi - - # get the revision list, and count the leading "<" and ">" - revgit=`git rev-list --left-right ${remote_ref}...HEAD` - num_revs=`all_lines "$revgit"` - num_ahead=`count_lines "$revgit" "^>"` - num_behind=$(( num_revs - num_ahead )) - if (( num_behind > 0 )) ; then + if [[ "${remote_line[1]}" == *behind* ]]; then + num_behind=`echo "${remote_line[1]}" | cut -c 9-` remote="${remote}_BEHIND_${num_behind}" fi - if (( num_ahead > 0 )) ; then - remote="${remote}_AHEAD_${num_ahead}" - fi fi if [[ -z "$remote" ]] ; then remote='.' fi -if [[ "$has_remote_tracking" == "0" ]] ; then - remote='_NO_REMOTE_TRACKING_' -fi - for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do echo "$w" done From 8e9faff94949907b40e2eaf8738b5b8da0e6cb48 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Sun, 20 Sep 2015 15:55:36 -0500 Subject: [PATCH 18/69] Fix issue parsing where there is no remote branch --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 59f3673..dbc0bc9 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -46,7 +46,7 @@ fi remote= -branch_line=`echo $gitstatus | grep "^##"` +branch_line=`echo "$gitstatus" | grep "^##"` IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" From 7f63c3b0c708ca0b30acfbb5d39b571269a6ffd7 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Mon, 21 Sep 2015 00:47:13 -0500 Subject: [PATCH 19/69] Fix a problem calculating clean in the python script --- gitstatus.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index 423619a..3b12c3b 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -119,7 +119,8 @@ for st in status: elif st[0] != ' ': staged.append(st) -if not changed and not staged and not conflicts and not untracked: +stashed=get_stash() +if not changed and not staged and not conflicts and not untracked and not stashed: clean = 1 else: clean = 0 @@ -134,7 +135,7 @@ out = '\n'.join([ str(len(conflicts)), str(len(changed)), str(len(untracked)), - str(get_stash()), + str(stashed), str(clean) ]) Print(out) From 0231552c4e66dd802008927104c32275d7daaa99 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Mon, 21 Sep 2015 10:18:15 -0500 Subject: [PATCH 20/69] use bash substring rather than cut --- gitstatus.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index dbc0bc9..234926d 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -65,11 +65,11 @@ elif [[ "$branch" == *"no branch"* ]]; then else IFS="[]" read -ra remote_line <<< "${line[3]}" if [[ "${remote_line[1]}" == *ahead* ]]; then - num_ahead=`echo "${remote_line[1]}" | cut -c 7-` + num_ahead=${remote_line[1]:6} remote="${remote}_AHEAD_${num_ahead}" fi if [[ "${remote_line[1]}" == *behind* ]]; then - num_behind=`echo "${remote_line[1]}" | cut -c 9-` + num_behind=${remote_line[1]:9} remote="${remote}_BEHIND_${num_behind}" fi fi From 00558b8de8ad43c7522651d517ac9baadd417ad0 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Mon, 21 Sep 2015 10:19:26 -0500 Subject: [PATCH 21/69] fix substring indexing --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 234926d..0d58678 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -69,7 +69,7 @@ else remote="${remote}_AHEAD_${num_ahead}" fi if [[ "${remote_line[1]}" == *behind* ]]; then - num_behind=${remote_line[1]:9} + num_behind=${remote_line[1]:8} remote="${remote}_BEHIND_${num_behind}" fi fi From d83795adcbb37aed26a3bb3484fb63f9ae4869b9 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 22 Sep 2015 07:10:32 +0200 Subject: [PATCH 22/69] Revert unset prompt_callback and extra call to git_prompt_reset --- gitprompt.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 97b12d0..da53548 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -65,7 +65,6 @@ function get_theme() { } function git_prompt_load_theme() { - git_prompt_reset get_theme local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" source "${DEFAULT_THEME_FILE}" @@ -179,7 +178,6 @@ git_prompt_reset() { for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD GIT_PROMPT_THEME_NAME; do unset $var done - unset -f prompt_callback } # gp_format_exit_status RETVAL From 0dbac24bba7515a59636abab91d97187c597459c Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Wed, 23 Sep 2015 17:19:47 +0900 Subject: [PATCH 23/69] Set LC_ALL=C at git status to make sure in English Fix https://github.com/magicmonty/bash-git-prompt/pull/170#issuecomment-142516122 --- gitstatus.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitstatus.py b/gitstatus.py index 423619a..48d91f5 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -74,7 +74,8 @@ def get_stash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, + stdout=PIPE, stderr=PIPE) stdout, sterr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository From 7418da801dddd67a17d89fae587191aedf893b98 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 09:22:56 -0500 Subject: [PATCH 24/69] Set LC_ALL=C to force branch output to English --- gitstatus.py | 3 ++- gitstatus.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index 3b12c3b..54ada71 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -74,7 +74,8 @@ def get_stash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, + stdout=PIPE, stderr=PIPE) stdout, sterr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository diff --git a/gitstatus.sh b/gitstatus.sh index 0d58678..cea824a 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -18,7 +18,7 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -gitstatus=`git status --porcelain --branch` +gitstatus=`LC_ALL=C git status --porcelain --branch` # if the status is fatal, exit now [[ "$?" -ne 0 ]] && exit 0 From 3a9239d227fa3476550c8fdb00160d5ae2e68f76 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 14:32:02 -0500 Subject: [PATCH 25/69] Fix issue where _NO_REMOTE_TRACKING_ doesn't show up when there is no remote branch --- gitstatus.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gitstatus.sh b/gitstatus.sh index cea824a..df90245 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -50,6 +50,10 @@ branch_line=`echo "$gitstatus" | grep "^##"` IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" +if [[ "${#line[@]}" -eq 1 ]]; then + remote="_NO_REMOTE_TRACKING_" +fi + if [[ -z "$branch" ]]; then tag=`git describe --exact-match` if [[ -n "$tag" ]]; then From e4c6b0ab9e9895968bd3fc08928eb22b7c850f9f Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 15:09:40 -0500 Subject: [PATCH 26/69] Remove calls to grep/egrep --- gitstatus.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index df90245..bb98436 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -5,9 +5,6 @@ # # Alan K. Stebbens [http://github.com/aks] -# helper functions -count_lines() { echo "$1" | egrep -c $3 "^$2" ; } - if [ -z "${__GIT_PROMPT_DIR}" ]; then SOURCE="${BASH_SOURCE[0]}" while [ -h "${SOURCE}" ]; do @@ -23,17 +20,27 @@ gitstatus=`LC_ALL=C git status --porcelain --branch` # if the status is fatal, exit now [[ "$?" -ne 0 ]] && exit 0 -num_staged=`count_lines "$gitstatus" "(\?\?|##| )" "-v"` -num_changed=`count_lines "$gitstatus" ".M"` -num_conflicts=`count_lines "$gitstatus" "U"` -num_untracked=`count_lines "$gitstatus" "\?\?"` +num_staged=0 +num_changed=0 +num_conflicts=0 +num_untracked=0 +while IFS='' read -r line || [[ -n "$line" ]]; do + status=${line:0:2} + case "$status" in + \#\#) branch_line="$line" ;; + *M) ((num_changed++)) ;; + U*) ((num_conflicts++)) ;; + \?\?) ((num_untracked++)) ;; + *) ((num_staged++)) ;; + esac +done <<< "$gitstatus" if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 else stash_file="`git rev-parse --git-dir`/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - num_stashed=`wc -l "${stash_file}" | cut -d' ' -f 1` + num_stashed=`cat "${stash_file} | wc -l` else num_stashed=0 fi @@ -46,7 +53,6 @@ fi remote= -branch_line=`echo "$gitstatus" | grep "^##"` IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" From 1e2ff372826abd8d51d9bb58c3fa6aff5b0dfb40 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 18:12:37 -0500 Subject: [PATCH 27/69] Switch case matches from * to ? --- gitstatus.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index bb98436..03e1bc1 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -28,8 +28,8 @@ while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} case "$status" in \#\#) branch_line="$line" ;; - *M) ((num_changed++)) ;; - U*) ((num_conflicts++)) ;; + ?M) ((num_changed++)) ;; + U?) ((num_conflicts++)) ;; \?\?) ((num_untracked++)) ;; *) ((num_staged++)) ;; esac From ff7aa3aa7a547c1555aaca435091ce257f465a8c Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 18:22:35 -0500 Subject: [PATCH 28/69] Fix handling of stash --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 03e1bc1..57876f7 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -40,7 +40,7 @@ if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then else stash_file="`git rev-parse --git-dir`/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - num_stashed=`cat "${stash_file} | wc -l` + num_stashed=`wc -l "${stash_file}" | cut -d' ' -f1` else num_stashed=0 fi From 545cdce3990f56b7734c4cc0accd6ff3fb4bb12a Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 18:29:44 -0500 Subject: [PATCH 29/69] Use printf instead of echo to display --- gitstatus.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 57876f7..e1e395d 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -88,8 +88,13 @@ if [[ -z "$remote" ]] ; then remote='.' fi -for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do - echo "$w" -done +printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ + "$branch" \ + "$remote" \ + $num_staged \ + $num_conflicts \ + $num_changed \ + $num_untracked \ + $num_stashed $clean exit From 01f5402c7713ee784f038d1705d26563f6b958f9 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 20:05:13 -0500 Subject: [PATCH 30/69] Fix behind parsing --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index df90245..a834f91 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -73,7 +73,7 @@ else remote="${remote}_AHEAD_${num_ahead}" fi if [[ "${remote_line[1]}" == *behind* ]]; then - num_behind=${remote_line[1]:8} + num_behind=${remote_line[1]:7} remote="${remote}_BEHIND_${num_behind}" fi fi From 606388df395f6ac166c23e1871cbadffc474b4e3 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Wed, 23 Sep 2015 20:05:13 -0500 Subject: [PATCH 31/69] Fix behind parsing --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index e1e395d..57a8afd 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -79,7 +79,7 @@ else remote="${remote}_AHEAD_${num_ahead}" fi if [[ "${remote_line[1]}" == *behind* ]]; then - num_behind=${remote_line[1]:8} + num_behind=${remote_line[1]:7} remote="${remote}_BEHIND_${num_behind}" fi fi From 220d5c22b126f27eb688cd2c1d68e4c07175d37b Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Thu, 24 Sep 2015 09:08:27 -0500 Subject: [PATCH 32/69] Fix parsing when both ahead and behind --- gitstatus.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 57a8afd..932804a 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -73,15 +73,17 @@ elif [[ "$branch" == *"Initial commit on"* ]]; then elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_`git rev-parse --short HEAD`" else - IFS="[]" read -ra remote_line <<< "${line[3]}" - if [[ "${remote_line[1]}" == *ahead* ]]; then - num_ahead=${remote_line[1]:6} - remote="${remote}_AHEAD_${num_ahead}" - fi - if [[ "${remote_line[1]}" == *behind* ]]; then - num_behind=${remote_line[1]:7} - remote="${remote}_BEHIND_${num_behind}" - fi + IFS="[,]" read -ra remote_line <<< "${line[3]}" + for rline in "${remote_line[@]}"; do + if [[ "$rline" == *ahead* ]]; then + num_ahead=${rline:6} + remote="${remote}_AHEAD_${num_ahead}" + fi + if [[ "$rline" == *behind* ]]; then + num_behind=${rline:7} + remote="${remote}_BEHIND_${num_behind# }" + fi + done fi if [[ -z "$remote" ]] ; then From 750425d8417478f098b04b8544ddb26d7d70d633 Mon Sep 17 00:00:00 2001 From: oGre Date: Thu, 24 Sep 2015 08:33:06 +0200 Subject: [PATCH 33/69] Changed all backticks to --- gitstatus.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 9cff1c4..b228b5a 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -15,7 +15,7 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -gitstatus=`LC_ALL=C git status --porcelain --branch` +gitstatus=$( LC_ALL=C git status --porcelain --branch ) # if the status is fatal, exit now [[ "$?" -ne 0 ]] && exit 0 @@ -38,9 +38,9 @@ done <<< "$gitstatus" if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 else - stash_file="`git rev-parse --git-dir`/logs/refs/stash" + stash_file="$( git rev-parse --git-dir )/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - num_stashed=`wc -l "${stash_file}" | cut -d' ' -f1` + num_stashed=$( wc -l "${stash_file}" | cut -d' ' -f1 ) else num_stashed=0 fi @@ -62,17 +62,17 @@ if [[ "${#line[@]}" -eq 1 ]]; then fi if [[ -z "$branch" ]]; then - tag=`git describe --exact-match` + tag=$( git describe --exact-match ) if [[ -n "$tag" ]]; then branch="$tag" else - branch="_PREHASH_`git rev-parse --short HEAD`" + branch="_PREHASH_$( git rev-parse --short HEAD )" fi elif [[ "$branch" == *"Initial commit on"* ]]; then IFS=" " read -ra branch_line <<< "$branch" branch=${branch_line[-1]} elif [[ "$branch" == *"no branch"* ]]; then - branch="_PREHASH_`git rev-parse --short HEAD`" + branch="_PREHASH_$( git rev-parse --short HEAD )" else IFS="[,]" read -ra remote_line <<< "${line[3]}" for rline in "${remote_line[@]}"; do From 0e48e020b8be82fbda22d1cf681b087a0f031944 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Thu, 24 Sep 2015 09:54:02 -0500 Subject: [PATCH 34/69] Remove unnecessary grep line --- gitstatus.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 9cff1c4..100b335 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -53,7 +53,6 @@ fi remote= -branch_line=`echo "$gitstatus" | grep "^##"` IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" From 87c66ea8d1d65b91519c5f032544321e064bcfd4 Mon Sep 17 00:00:00 2001 From: oGre Date: Thu, 24 Sep 2015 17:28:20 +0200 Subject: [PATCH 35/69] Missed one --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index b228b5a..a83e91b 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -53,7 +53,7 @@ fi remote= -branch_line=`echo "$gitstatus" | grep "^##"` +branch_line=$( echo "$gitstatus" | grep "^##" ) IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" From db6f2195538982482feba56ae411d78ed391d252 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Thu, 24 Sep 2015 10:40:18 -0500 Subject: [PATCH 36/69] Reorder AHEAD and BEHIND --- gitstatus.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 100b335..04bce5a 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -77,13 +77,14 @@ else for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} - remote="${remote}_AHEAD_${num_ahead}" + ahead="_AHEAD_${num_ahead}" fi if [[ "$rline" == *behind* ]]; then num_behind=${rline:7} - remote="${remote}_BEHIND_${num_behind# }" + behind="_BEHIND_${num_behind# }" fi done + remote="${behind}${ahead}" fi if [[ -z "$remote" ]] ; then From 9955edb5c373938b947379182a916adaaf40a7ab Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 25 Sep 2015 07:22:52 +0200 Subject: [PATCH 37/69] Check for local branch needs to be moved so that check for behind/after doesn't override the result --- gitstatus.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 2f15540..a7b9c65 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -56,10 +56,6 @@ remote= IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" -if [[ "${#line[@]}" -eq 1 ]]; then - remote="_NO_REMOTE_TRACKING_" -fi - if [[ -z "$branch" ]]; then tag=$( git describe --exact-match ) if [[ -n "$tag" ]]; then @@ -73,18 +69,22 @@ elif [[ "$branch" == *"Initial commit on"* ]]; then elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_$( git rev-parse --short HEAD )" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" - for rline in "${remote_line[@]}"; do - if [[ "$rline" == *ahead* ]]; then - num_ahead=${rline:6} - ahead="_AHEAD_${num_ahead}" - fi - if [[ "$rline" == *behind* ]]; then - num_behind=${rline:7} - behind="_BEHIND_${num_behind# }" - fi - done - remote="${behind}${ahead}" + if [[ "${#line[@]}" -eq 1 ]]; then + remote="_NO_REMOTE_TRACKING_" + else + IFS="[,]" read -ra remote_line <<< "${line[3]}" + for rline in "${remote_line[@]}"; do + if [[ "$rline" == *ahead* ]]; then + num_ahead=${rline:6} + ahead="_AHEAD_${num_ahead}" + fi + if [[ "$rline" == *behind* ]]; then + num_behind=${rline:7} + behind="_BEHIND_${num_behind# }" + fi + done + remote="${behind}${ahead}" + fi fi if [[ -z "$remote" ]] ; then From b989b7f324cf7c2d04eca941916395b4a05252b7 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 25 Sep 2015 12:30:29 +0200 Subject: [PATCH 38/69] Able to parse tag names when on tag --- gitstatus.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index a7b9c65..fc48cf7 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -56,18 +56,16 @@ remote= IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" -if [[ -z "$branch" ]]; then +if [[ "$branch" == *"Initial commit on"* ]]; then + IFS=" " read -ra branch_line <<< "$branch" + branch=${branch_line[-1]} +elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --exact-match ) if [[ -n "$tag" ]]; then branch="$tag" else branch="_PREHASH_$( git rev-parse --short HEAD )" fi -elif [[ "$branch" == *"Initial commit on"* ]]; then - IFS=" " read -ra branch_line <<< "$branch" - branch=${branch_line[-1]} -elif [[ "$branch" == *"no branch"* ]]; then - branch="_PREHASH_$( git rev-parse --short HEAD )" else if [[ "${#line[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" From c5cac48f4d85c012a76861450067019db518c4f1 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 25 Sep 2015 12:59:48 +0200 Subject: [PATCH 39/69] Initial commit on is always a local state - set no remote tracking --- gitstatus.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitstatus.sh b/gitstatus.sh index fc48cf7..7782e62 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -59,6 +59,7 @@ branch="${line[0]}" if [[ "$branch" == *"Initial commit on"* ]]; then IFS=" " read -ra branch_line <<< "$branch" branch=${branch_line[-1]} + remote="_NO_REMOTE_TRACKING_" elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --exact-match ) if [[ -n "$tag" ]]; then From 3621b5a67c3ea87d47e8679c4a12117d09d23125 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 25 Sep 2015 19:41:07 +0200 Subject: [PATCH 40/69] We set branch first, then remote --- gitstatus.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 7782e62..e01e00d 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -51,10 +51,9 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = clean=1 fi -remote= - IFS="." read -ra line <<< "${branch_line/\#\# }" branch="${line[0]}" +remote= if [[ "$branch" == *"Initial commit on"* ]]; then IFS=" " read -ra branch_line <<< "$branch" From 5fe390d098974932939290df4eca194e97ece7b7 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 25 Sep 2015 22:28:40 +0200 Subject: [PATCH 41/69] Fixed bug in stash parsing --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index e01e00d..3b87cf0 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -40,7 +40,7 @@ if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then else stash_file="$( git rev-parse --git-dir )/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - num_stashed=$( wc -l "${stash_file}" | cut -d' ' -f1 ) + num_stashed=$( wc -l < "${stash_file}" | tr -s ' ' | cut -d ' ' -f2 ) else num_stashed=0 fi From c279c77fd8437a813a838083de39506f9dfe2ec8 Mon Sep 17 00:00:00 2001 From: oGre Date: Sun, 27 Sep 2015 18:14:52 +0200 Subject: [PATCH 42/69] Resolved conflict --- gitstatus.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 3b87cf0..c2a8e40 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -40,7 +40,8 @@ if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then else stash_file="$( git rev-parse --git-dir )/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - num_stashed=$( wc -l < "${stash_file}" | tr -s ' ' | cut -d ' ' -f2 ) + wc_output=$( wc -l < "${stash_file}" ) + num_stashed=${wc_output// /} else num_stashed=0 fi From 89acb1c4b0925cf40d1d016c2610552836f310db Mon Sep 17 00:00:00 2001 From: oGre Date: Sun, 27 Sep 2015 18:43:30 +0200 Subject: [PATCH 43/69] Changed to match tabs and spaces --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index c2a8e40..9b763e0 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -41,7 +41,7 @@ else stash_file="$( git rev-parse --git-dir )/logs/refs/stash" if [[ -e "${stash_file}" ]]; then wc_output=$( wc -l < "${stash_file}" ) - num_stashed=${wc_output// /} + num_stashed=${wc_output//[[:space:]]/} else num_stashed=0 fi From 1786764bc1df05a571fd86f6cc44ef54cbeea4fd Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Sun, 27 Sep 2015 11:53:42 -0500 Subject: [PATCH 44/69] Remove use of wc --- gitstatus.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 9b763e0..d03f197 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -35,15 +35,13 @@ while IFS='' read -r line || [[ -n "$line" ]]; do esac done <<< "$gitstatus" -if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then - num_stashed=0 -else +num_stashed=0 +if [[ "$__GIT_PROMPT_IGNORE_STASH" != "1" ]]; then stash_file="$( git rev-parse --git-dir )/logs/refs/stash" if [[ -e "${stash_file}" ]]; then - wc_output=$( wc -l < "${stash_file}" ) - num_stashed=${wc_output//[[:space:]]/} - else - num_stashed=0 + while IFS='' read -r wcline || [[ -n "$wcline" ]]; do + ((num_stashed++)) + done < ${stash_file} fi fi From 1603b30f710eb7ef69aa336dbf1b64eab352cb4f Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 27 Sep 2015 23:11:18 +0200 Subject: [PATCH 45/69] Fixes error on freshly initialized repository --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index d03f197..5416fec 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -56,7 +56,7 @@ remote= if [[ "$branch" == *"Initial commit on"* ]]; then IFS=" " read -ra branch_line <<< "$branch" - branch=${branch_line[-1]} + branch="${branch_line[3]}" remote="_NO_REMOTE_TRACKING_" elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --exact-match ) From 249c24e279d6394c152c7aa3b2f0a29caa6f896b Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 07:05:59 +0200 Subject: [PATCH 46/69] Two functions missed. --- gitprompt.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index ed60902..1913b5b 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -189,16 +189,16 @@ git_prompt_reset() { # signalled, otherwise echos the original value of RETVAL gp_format_exit_status() { - local RETVAL="$1" - local SIGNAL - # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL - # is echoed verbatim) - if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then - SIGNAL=$(( ${RETVAL} - 128 )) - kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" - else - echo "${RETVAL}" - fi + local RETVAL="$1" + local SIGNAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # is echoed verbatim) + if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then + SIGNAL=$(( ${RETVAL} - 128 )) + kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" + else + echo "${RETVAL}" + fi } function git_prompt_config() { @@ -427,11 +427,11 @@ function replaceSymbols() GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L fi - local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} - local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} - echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } function updatePrompt() { From 09fcaf22fc4593af1c3e048b39548aab4cd87f0d Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 18:23:05 +0200 Subject: [PATCH 47/69] Optimized theme reading to not use external commands, but only bash --- gitprompt.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 17568d6..2f1a90e 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -49,8 +49,9 @@ function get_theme() { local theme="" # use default theme, if theme was not found - for themefile in $(cd "$__GIT_PROMPT_DIR/themes" && echo *); do - if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then + for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + local basename=${themefile##*/} + if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME fi done @@ -78,9 +79,9 @@ function git_prompt_list_themes() { git_prompt_dir get_theme - for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do - local theme="$(basename $themefile .bgptheme)" - + for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + local basename=${themefile##*/} + local theme="${basename%.bgptheme}" if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then echoc ${Red} "*${theme}" else @@ -319,7 +320,7 @@ function update_old_git_prompt() { function setGitPrompt() { update_old_git_prompt - local repo=`git rev-parse --show-toplevel 2> /dev/null` + local repo=$(git rev-parse --show-toplevel 2> /dev/null) if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then # we do not permit bash-git-prompt outside git repos, so nothing to do PS1="$OLD_GITPROMPT" @@ -375,7 +376,7 @@ function olderThanMinutes() { fi if [[ "$_have_find_mmin" = 1 ]]; then - matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` + matches=$("$_find_command" "$1" -mmin +"$2" 2> /dev/null) find_exit_code="$?" if [[ -n "$matches" ]]; then return 0 From 2e0180f93a9ad3fc0444aae5c8de706c11c7ad3b Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 18:33:11 +0200 Subject: [PATCH 48/69] Removed backtick from comment --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 2f1a90e..99c2d21 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -206,7 +206,7 @@ function git_prompt_config() { # There are two files related to colors: # - # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt + # prompt-colors.sh -- sets generic color names suitable for bash 'PS1' prompt # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then From f319f3acc1d9d207f537e868fbad27f5652fcc25 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 21:29:39 +0200 Subject: [PATCH 49/69] Added break in loop after we find the current theme --- gitprompt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitprompt.sh b/gitprompt.sh index 99c2d21..b106db9 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -53,6 +53,7 @@ function get_theme() { local basename=${themefile##*/} if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME + break fi done From f1940dfe8bf7afea862e7d69f082022a975b1dfa Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 22:14:48 +0200 Subject: [PATCH 50/69] Quoted paths to handle spaces in them --- gitprompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index b106db9..00a79c2 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -49,7 +49,7 @@ function get_theme() { local theme="" # use default theme, if theme was not found - for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do local basename=${themefile##*/} if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME @@ -80,7 +80,7 @@ function git_prompt_list_themes() { git_prompt_dir get_theme - for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do local basename=${themefile##*/} local theme="${basename%.bgptheme}" if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then From d4b630bf7d62a323c4d1424d0c79b7b841603e05 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 29 Sep 2015 17:00:14 +0200 Subject: [PATCH 51/69] Possible to have dots in branch name --- gitstatus.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 5416fec..ebebd8d 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -50,8 +50,9 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = clean=1 fi -IFS="." read -ra line <<< "${branch_line/\#\# }" -branch="${line[0]}" +branch="${branch_line#\#\# }" +branch="${branch%\.\.\.*}" +remote_branch_and_diff="${branch_line#*\.\.\.}" remote= if [[ "$branch" == *"Initial commit on"* ]]; then @@ -66,10 +67,10 @@ elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_$( git rev-parse --short HEAD )" fi else - if [[ "${#line[@]}" -eq 1 ]]; then + if [[ "${remote_branch_and_diff}" == "${branch_line}" ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${remote_branch_and_diff}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From 73f3cb75d19f586e8baca0347d93e6c70a3814f6 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Tue, 29 Sep 2015 15:44:25 -0500 Subject: [PATCH 52/69] Handle branches with dots in them --- gitstatus.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 5416fec..3343889 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -27,7 +27,7 @@ num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} case "$status" in - \#\#) branch_line="$line" ;; + \#\#) branch_line="${line/\.\.\./^}" ;; ?M) ((num_changed++)) ;; U?) ((num_conflicts++)) ;; \?\?) ((num_untracked++)) ;; @@ -50,13 +50,13 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = clean=1 fi -IFS="." read -ra line <<< "${branch_line/\#\# }" -branch="${line[0]}" +IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }" +branch="${branch_fields[0]}" remote= if [[ "$branch" == *"Initial commit on"* ]]; then - IFS=" " read -ra branch_line <<< "$branch" - branch="${branch_line[3]}" + IFS=" " read -ra fields <<< "$branch" + branch="${fields[3]}" remote="_NO_REMOTE_TRACKING_" elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --exact-match ) @@ -66,10 +66,10 @@ elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_$( git rev-parse --short HEAD )" fi else - if [[ "${#line[@]}" -eq 1 ]]; then + if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From dedb19180bb4ab8570425074752535f37528a480 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Tue, 29 Sep 2015 18:10:16 -0500 Subject: [PATCH 53/69] fix issue with parsing ahead/behind --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index e30d29e..3343889 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -69,7 +69,7 @@ else if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From ca7a848ca4efb8cfabb7275bfdbf469b08faa367 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 30 Sep 2015 16:34:09 +0200 Subject: [PATCH 54/69] Renamed array variable to _fields to comply with the other arrays --- gitstatus.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 3343889..9f345e5 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -69,14 +69,14 @@ else if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" - for rline in "${remote_line[@]}"; do - if [[ "$rline" == *ahead* ]]; then - num_ahead=${rline:6} + IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}" + for remote_field in "${remote_fields[@]}"; do + if [[ "$remote_field" == *ahead* ]]; then + num_ahead=${remote_field:6} ahead="_AHEAD_${num_ahead}" fi - if [[ "$rline" == *behind* ]]; then - num_behind=${rline:7} + if [[ "$remote_field" == *behind* ]]; then + num_behind=${remote_field:7} behind="_BEHIND_${num_behind# }" fi done From ba1276e9c8db134745b406a2d124cca1702f1d82 Mon Sep 17 00:00:00 2001 From: oGre Date: Thu, 1 Oct 2015 21:56:14 +0200 Subject: [PATCH 55/69] Honor VIRTUAL_ENV_DISABLE_PROMPT, if it is set to non-empty string --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 00a79c2..a08cde4 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -273,7 +273,7 @@ function git_prompt_config() { EMPTY_PROMPT="$OLD_GITPROMPT" else local ps="" - if [[ -n "$VIRTUAL_ENV" ]]; then + if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then VENV=$(basename "${VIRTUAL_ENV}") ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi From 26bd9fb35400e9ec1d7f30a2e8fd1a947c858850 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 2 Oct 2015 07:10:33 +0200 Subject: [PATCH 56/69] Honor VIRTUAL_ENV_DISABLE_PROMPT in updatePrompt as well --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index a08cde4..82f1a74 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -501,7 +501,7 @@ function updatePrompt() { __add_status "$ResetColor$GIT_PROMPT_SUFFIX" NEW_PROMPT="" - if [[ -n "$VIRTUAL_ENV" ]]; then + if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then VENV=$(basename "${VIRTUAL_ENV}") NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi From 149efc1331bd7d657f8ce40ffda10ff8da50d048 Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 2 Oct 2015 08:33:20 +0200 Subject: [PATCH 57/69] Virtualenv information duplicated code moved to helper function --- gitprompt.sh | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 82f1a74..4a5f30a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -272,16 +272,7 @@ function git_prompt_config() { if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then EMPTY_PROMPT="$OLD_GITPROMPT" else - local ps="" - if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then - VENV=$(basename "${VIRTUAL_ENV}") - ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" - fi - if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - VENV=$(basename "${CONDA_DEFAULT_ENV}") - ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" - fi - ps="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" + local ps="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$PROMPT_END" EMPTY_PROMPT="${ps//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" fi @@ -500,18 +491,7 @@ function updatePrompt() { __chk_gitvar_status 'CLEAN' '-eq 1' - __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - NEW_PROMPT="" - if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then - VENV=$(basename "${VIRTUAL_ENV}") - NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" - fi - - if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - VENV=$(basename "${CONDA_DEFAULT_ENV}") - NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" - fi - - NEW_PROMPT="$NEW_PROMPT$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + NEW_PROMPT="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" else NEW_PROMPT="$EMPTY_PROMPT" fi @@ -519,6 +499,22 @@ function updatePrompt() { PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" } +# Helper function that returns virtual env information to be set in prompt +# Honors virtualenvs own setting VIRTUAL_ENV_DISABLE_PROMPT +function gp_add_virtualenv_to_prompt { + local ACCUMULATED_VENV_PROMPT="" + local VENV="" + if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then + VENV=$(basename "${VIRTUAL_ENV}") + ACCUMULATED_VENV_PROMPT="${ACCUMULATED_VENV_PROMPT}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" + fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + ACCUMULATED_VENV_PROMPT="${ACCUMULATED_VENV_PROMPT}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" + fi + echo "$ACCUMULATED_VENV_PROMPT" +} + # Use exit status from declare command to determine whether input argument is a # bash function function is_function { From dd324dcdb2562b199043aa12177bc53f494e0350 Mon Sep 17 00:00:00 2001 From: oGre Date: Sun, 4 Oct 2015 20:56:19 +0200 Subject: [PATCH 58/69] Re-format, moved imports, fixed spelling error --- gitstatus.py | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index 1e1f385..a027c10 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -8,38 +8,39 @@ http://docs.python.org/3.0/library/functions.html?highlight=print#print Shamelessly ripped from http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python """ - -__all__ = ["Print"] -import sys -try: - Print = eval("print") # python 3.0 case -except SyntaxError: - try: - D = dict() - exec("from __future__ import print_function\np=print", D) - Print = D["p"] # 2.6 case - del D - except SyntaxError: - del D - def Print(*args, **kwd): # 2.4, 2.5, define our own Print function - fout = kwd.get("file", sys.stdout) - w = fout.write - if args: - w(str(args[0])) - sep = kwd.get("sep", " ") - for a in args[1:]: - w(sep) - w(str(a)) - w(kwd.get("end", "\n")) - # change those symbols to whatever you prefer -symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'} +symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash': ':'} import sys import re import shlex from subprocess import Popen, PIPE, check_output +__all__ = ["Print"] + +try: + Print = eval("print") # python 3.0 case +except SyntaxError: + try: + D = dict() + exec ("from __future__ import print_function\np=print", D) + Print = D["p"] # 2.6 case + del D + except SyntaxError: + del D + + + def Print(*args, **kwd): # 2.4, 2.5, define our own Print function + fout = kwd.get("file", sys.stdout) + w = fout.write + if args: + w(str(args[0])) + sep = kwd.get("sep", " ") + for a in args[1:]: + w(sep) + w(str(a)) + w(kwd.get("end", "\n")) + def get_tagname_or_hash(): """return tagname if exists else hash""" @@ -49,11 +50,11 @@ def get_tagname_or_hash(): # get hash m = re.search('\(.*\)$', output) if m: - hash_ = output[:m.start()-1] + hash_ = output[:m.start() - 1] # get tagname m = re.search('tag: .*[,\)]', output) if m: - tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1] + tagname = 'tags/' + output[m.start() + len('tag: '): m.end() - 1] if tagname: return tagname @@ -61,10 +62,11 @@ def get_tagname_or_hash(): return hash_ return None + def get_stash(): cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE) so, se = cmd.communicate() - stashFile = '%s%s' % (so.decode('utf-8').rstrip(),'/logs/refs/stash') + stashFile = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash') try: with open(stashFile) as f: @@ -72,11 +74,12 @@ def get_stash(): except IOError: return 0 + # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, stdout=PIPE, stderr=PIPE) -stdout, sterr = po.communicate() +stdout, stderr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository @@ -120,7 +123,7 @@ for st in status: elif st[0] != ' ': staged.append(st) -stashed=get_stash() +stashed = get_stash() if not changed and not staged and not conflicts and not untracked and not stashed: clean = 1 else: From 1170818d0481c94da89f985670c49e480e1ee641 Mon Sep 17 00:00:00 2001 From: oGre Date: Sun, 4 Oct 2015 21:46:39 +0200 Subject: [PATCH 59/69] Refactored get tag or hash to work as the bash version --- gitstatus.py | 68 +++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index a027c10..cca3010 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -1,35 +1,32 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -"""This module defines a Print function to use with python 2.x or 3.x., so we can use the prompt with older versions of Python too +"""This module defines a Print function to use with python 2.x or 3.x., so we can use the prompt with older versions of +Python too It's interface is that of python 3.0's print. See http://docs.python.org/3.0/library/functions.html?highlight=print#print -Shamelessly ripped from http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python +Shamelessly ripped from +http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python """ # change those symbols to whatever you prefer symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash': ':'} import sys import re -import shlex -from subprocess import Popen, PIPE, check_output +from subprocess import Popen, PIPE __all__ = ["Print"] try: Print = eval("print") # python 3.0 case except SyntaxError: + D = dict() try: - D = dict() exec ("from __future__ import print_function\np=print", D) Print = D["p"] # 2.6 case - del D except SyntaxError: - del D - - def Print(*args, **kwd): # 2.4, 2.5, define our own Print function fout = kwd.get("file", sys.stdout) w = fout.write @@ -40,36 +37,31 @@ except SyntaxError: w(sep) w(str(a)) w(kwd.get("end", "\n")) + finally: + del D -def get_tagname_or_hash(): - """return tagname if exists else hash""" - cmd = 'git log -1 --format="%h%d"' - output = check_output(shlex.split(cmd)).decode('utf-8').strip() - hash_, tagname = None, None - # get hash - m = re.search('\(.*\)$', output) - if m: - hash_ = output[:m.start() - 1] - # get tagname - m = re.search('tag: .*[,\)]', output) - if m: - tagname = 'tags/' + output[m.start() + len('tag: '): m.end() - 1] +def get_tag_or_hash(): + cmd = Popen(['git', 'describe', '--exact-match'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + tag = '%s' % so.decode('utf-8').strip() - if tagname: - return tagname - elif hash_: - return hash_ - return None + if tag: + return tag + else: + cmd = Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + hash_name = '%s' % so.decode('utf-8').strip() + return symbols['prehash'] + hash_name def get_stash(): cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE) so, se = cmd.communicate() - stashFile = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash') + stash_file = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash') try: - with open(stashFile) as f: + with open(stash_file) as f: return sum(1 for _ in f) except IOError: return 0 @@ -85,7 +77,9 @@ if po.returncode != 0: # collect git status information untracked, staged, changed, conflicts = [], [], [], [] -ahead, behind = 0, 0 +num_ahead, num_behind = 0, 0 +ahead, behind = '', '' +branch = '' remote = '' status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()] for st in status: @@ -93,7 +87,7 @@ for st in status: if re.search('Initial commit on', st[2]): branch = st[2].split(' ')[-1] elif re.search('no branch', st[2]): # detached status - branch = get_tagname_or_hash() + branch = get_tag_or_hash() elif len(st[2].strip().split('...')) == 1: branch = st[2].strip() else: @@ -108,11 +102,15 @@ for st in status: divergence = divergence.lstrip('[').rstrip(']') for div in divergence.split(', '): if 'ahead' in div: - ahead = int(div[len('ahead '):].strip()) - remote += '%s%s' % (symbols['ahead of'], ahead) + num_ahead = int(div[len('ahead '):].strip()) + ahead = '%s%s' % (symbols['ahead of'], num_ahead) elif 'behind' in div: - behind = int(div[len('behind '):].strip()) - remote += '%s%s' % (symbols['behind'], behind) + num_behind = int(div[len('behind '):].strip()) + behind = '%s%s' % (symbols['behind'], num_behind) + remote = ''.join([ + behind, + ahead + ]) elif st[0] == '?' and st[1] == '?': untracked.append(st) else: From 55becdb193d57ba8e94e9a5d1146a78ca15acdd4 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 5 Oct 2015 07:11:57 +0200 Subject: [PATCH 60/69] Minor reformatting --- gitstatus.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index cca3010..da175ba 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -52,7 +52,7 @@ def get_tag_or_hash(): cmd = Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=PIPE, stderr=PIPE) so, se = cmd.communicate() hash_name = '%s' % so.decode('utf-8').strip() - return symbols['prehash'] + hash_name + return ''.join([symbols['prehash'], hash_name]) def get_stash(): @@ -69,8 +69,7 @@ def get_stash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, - stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, stdout=PIPE, stderr=PIPE) stdout, stderr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository @@ -107,10 +106,7 @@ for st in status: elif 'behind' in div: num_behind = int(div[len('behind '):].strip()) behind = '%s%s' % (symbols['behind'], num_behind) - remote = ''.join([ - behind, - ahead - ]) + remote = ''.join([behind, ahead]) elif st[0] == '?' and st[1] == '?': untracked.append(st) else: From 1ba48fd06b9f15920a502d5e5698e5a188844335 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 5 Oct 2015 18:27:13 +0200 Subject: [PATCH 61/69] Added helper function gp_set_window_title that can be used to set XTerm window title to the given argument. Used in TruncatedPwd_WindowTitle theme --- gitprompt.sh | 5 +++++ themes/TruncatedPwd_WindowTitle.bgptheme | 7 +------ themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 7 +------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 00a79c2..65dc759 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -525,6 +525,11 @@ function is_function { declare -Ff "$1" >/dev/null; } +#Sets the window title to the given argument string +function gp_set_window_title { + echo -ne "\033]0;"$@"\007" +} + function prompt_callback_default { return } diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 3c2c4cc..29721c9 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -23,11 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" - #Sets the window title to the given argument string - function gp_set_title { - echo -ne "\033]0;"$@"\007" - } - #Helper function that truncates $PWD depending on window width function gp_truncate_pwd { local newPWD="${PWD/#$HOME/~}" @@ -39,7 +34,7 @@ override_git_prompt_colors() { #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" - gp_set_title $PS1 + gp_set_window_title "$PS1" echo -n "[${PS1}]${ResetColor}" } diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index fdd0f50..9feca37 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -23,11 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" - #Sets the window title to the given argument string - function gp_set_title { - echo -ne "\033]0;"$@"\007" - } - #Helper function that truncates $PWD depending on window width function gp_truncate_pwd { local newPWD="${PWD/#$HOME/~}" @@ -39,7 +34,7 @@ override_git_prompt_colors() { #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" - gp_set_title $PS1 + gp_set_window_title $PS1 echo -n "[${PS1}]${ResetColor}" } From ff48c815879807be8ff8f9f7500bf1629ca8f757 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 5 Oct 2015 18:29:04 +0200 Subject: [PATCH 62/69] Minor fix --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 9feca37..5a1bff1 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -34,7 +34,7 @@ override_git_prompt_colors() { #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" - gp_set_window_title $PS1 + gp_set_window_title "$PS1" echo -n "[${PS1}]${ResetColor}" } From fbeaa6effd84f1f01df61d3f05efeb32b8901b53 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 6 Oct 2015 08:55:18 +0200 Subject: [PATCH 63/69] Moved gp_truncate_pwd function to gitprompt.sh --- gitprompt.sh | 8 ++++++++ themes/TruncatedPwd_WindowTitle.bgptheme | 8 -------- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 8 -------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 65dc759..e812a85 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -525,6 +525,14 @@ function is_function { declare -Ff "$1" >/dev/null; } +#Helper function that truncates $PWD depending on window width +function gp_truncate_pwd { + local newPWD="${PWD/#$HOME/~}" + local pwdmaxlen=$((${COLUMNS:-80}/3)) + [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" + echo -n "$newPWD" +} + #Sets the window title to the given argument string function gp_set_window_title { echo -ne "\033]0;"$@"\007" diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 29721c9..b7f94e2 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -23,14 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" - #Helper function that truncates $PWD depending on window width - function gp_truncate_pwd { - local newPWD="${PWD/#$HOME/~}" - local pwdmaxlen=$((${COLUMNS:-80}/3)) - [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" - echo -n "$newPWD" - } - #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 5a1bff1..6e63676 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -23,14 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" - #Helper function that truncates $PWD depending on window width - function gp_truncate_pwd { - local newPWD="${PWD/#$HOME/~}" - local pwdmaxlen=$((${COLUMNS:-80}/3)) - [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" - echo -n "$newPWD" - } - #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" From 7edc0233fe7eba04361221f6baf9750f9c18dd04 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 6 Oct 2015 17:36:52 +0200 Subject: [PATCH 64/69] Updated documentation --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 09a24f9..278de6f 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,10 @@ function prompt_callback { } ``` +- There are two helper functions that can be used within `prompt_callback`: + - `gp_set_window_title ` - sets the window title to the given string (should work for XTerm type terminals like in OS X or Ubuntu) + - `gp_truncate_pwd` - a function that returns the current PWD truncated to fit the current terminal width + - If you want to show the git prompt only if you are in a git repository you can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script From 47f4aca1f80c9a41833009152fcc52c9360b8a66 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 13 Oct 2015 12:53:10 +0200 Subject: [PATCH 65/69] Added environment variable GIT_PROMPT_STATUS_COMMAND that can point out a custom gitstatus.sh script if needed. --- gitstatus_pre-1.7.10.sh | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 gitstatus_pre-1.7.10.sh diff --git a/gitstatus_pre-1.7.10.sh b/gitstatus_pre-1.7.10.sh new file mode 100644 index 0000000..4370288 --- /dev/null +++ b/gitstatus_pre-1.7.10.sh @@ -0,0 +1,112 @@ +#!/bin/bash +# -*- coding: UTF-8 -*- +# gitstatus.sh -- produce the current git repo status on STDOUT +# Functionally equivalent to 'gitstatus.py', but written in bash (not python). +# +# Alan K. Stebbens [http://github.com/aks] + +# helper functions +count_lines() { echo "$1" | egrep -c "^$2" ; } +all_lines() { echo "$1" | grep -v "^$" | wc -l ; } + +if [ -z "${__GIT_PROMPT_DIR}" ]; then + SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + done + __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" +fi + +gitsym=`git symbolic-ref HEAD` + +# if "fatal: Not a git repo .., then exit +case "$gitsym" in fatal*) exit 0 ;; esac + +# the current branch is the tail end of the symbolic reference +branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" + +gitstatus=`git diff --name-status 2>&1` + +# if the diff is fatal, exit now +case "$gitstatus" in fatal*) exit 0 ;; esac + + +staged_files=`git diff --staged --name-status` + +num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) +num_conflicts=`count_lines "$staged_files" U` +num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) +num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` +if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then + num_stashed=0 +else + num_stashed=`git stash list | wc -l` +fi + +clean=0 +if (( num_changed == 0 && num_staged == 0 && num_U == 0 && num_untracked == 0 && num_stashed == 0 )) ; then + clean=1 +fi + +remote= + +if [[ -z "$branch" ]]; then + tag=`git describe --exact-match` + if [[ -n "$tag" ]]; then + branch="$tag" + else + branch="_PREHASH_`git rev-parse --short HEAD`" + fi +else + remote_name=`git config branch.${branch}.remote` + + if [[ -n "$remote_name" ]]; then + merge_name=`git config branch.${branch}.merge` + else + remote_name='origin' + merge_name="refs/heads/${branch}" + fi + + if [[ "$remote_name" == '.' ]]; then + remote_ref="$merge_name" + else + remote_ref="refs/remotes/$remote_name/${merge_name##refs/heads/}" + fi + + # detect if the local branch have a remote tracking branch + cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) + + if [[ $? == 0 ]]; then + has_remote_tracking=1 + else + has_remote_tracking=0 + fi + + # get the revision list, and count the leading "<" and ">" + revgit=`git rev-list --left-right ${remote_ref}...HEAD` + num_revs=`all_lines "$revgit"` + num_ahead=`count_lines "$revgit" "^>"` + num_behind=$(( num_revs - num_ahead )) + if (( num_behind > 0 )) ; then + remote="${remote}_BEHIND_${num_behind}" + fi + if (( num_ahead > 0 )) ; then + remote="${remote}_AHEAD_${num_ahead}" + fi +fi + +if [[ -z "$remote" ]] ; then + remote='.' +fi + +if [[ "$has_remote_tracking" == "0" ]] ; then + remote='_NO_REMOTE_TRACKING_' +fi + +for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do + echo "$w" +done + +exit From 09c98facb69662ab2657ccf0b2a476515ff16672 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 13 Oct 2015 12:59:05 +0200 Subject: [PATCH 66/69] Added environment variable GIT_PROMPT_STATUS_COMMAND that can point out a custom gitstatus.sh script if needed. --- gitprompt.sh | 5 ++--- gitstatus_pre-1.7.10.sh | 0 themes/Default.bgptheme | 11 +++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) mode change 100644 => 100755 gitstatus_pre-1.7.10.sh diff --git a/gitprompt.sh b/gitprompt.sh index 5f3a4fe..178c6d1 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -282,8 +282,8 @@ function git_prompt_config() { fi if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir - if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" ; then - echo 1>&2 "Cannot find gitstatus.sh!" + if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/$GIT_PROMPT_STATUS_COMMAND" ; then + echo 1>&2 "Cannot find $GIT_PROMPT_STATUS_COMMAND!" fi # __GIT_STATUS_CMD defined fi @@ -520,7 +520,6 @@ function gp_add_virtualenv_to_prompt { function is_function { declare -Ff "$1" >/dev/null; } - #Helper function that truncates $PWD depending on window width function gp_truncate_pwd { local newPWD="${PWD/#$HOME/~}" diff --git a/gitstatus_pre-1.7.10.sh b/gitstatus_pre-1.7.10.sh old mode 100644 new mode 100755 diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index b37b0e3..40c97ec 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -16,6 +16,7 @@ unset_git_prompt_colors() { unset GIT_PROMPT_CLEAN unset GIT_PROMPT_COMMAND_OK unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_STATUS_COMMAND unset GIT_PROMPT_VIRTUALENV unset GIT_PROMPT_START_USER unset GIT_PROMPT_START_ROOT @@ -51,7 +52,7 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ # will be replaced with the exit code of the last command # e.g. # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 @@ -60,11 +61,13 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"; fi # indicator if the last command returned with an exit code of other than 0 + if [[ -z ${GIT_PROMPT_STATUS_COMMAND} ]]; then GIT_PROMPT_STATUS_COMMAND="gitstatus.sh"; fi # Point out the command to get the gitstatus from + # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with + # use the placeholder _VIRTUALENV_ will be replaced with # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi - + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi @@ -75,7 +78,7 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found - if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked } # call only from theme file From 50ee0e5fc980ab882be52d8d1d951efbb38bb76e Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 13 Oct 2015 18:24:57 +0200 Subject: [PATCH 67/69] Backported the new way of counting stashed files and the printf function to speed it up --- gitstatus_pre-1.7.10.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/gitstatus_pre-1.7.10.sh b/gitstatus_pre-1.7.10.sh index 4370288..f613709 100755 --- a/gitstatus_pre-1.7.10.sh +++ b/gitstatus_pre-1.7.10.sh @@ -39,10 +39,15 @@ num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` -if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then - num_stashed=0 -else - num_stashed=`git stash list | wc -l` + +num_stashed=0 +if [[ "$__GIT_PROMPT_IGNORE_STASH" != "1" ]]; then + stash_file="$( git rev-parse --git-dir )/logs/refs/stash" + if [[ -e "${stash_file}" ]]; then + while IFS='' read -r wcline || [[ -n "$wcline" ]]; do + ((num_stashed++)) + done < ${stash_file} + fi fi clean=0 @@ -105,8 +110,14 @@ if [[ "$has_remote_tracking" == "0" ]] ; then remote='_NO_REMOTE_TRACKING_' fi -for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do - echo "$w" -done +printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ + "$branch" \ + "$remote" \ + $num_staged \ + $num_conflicts \ + $num_changed \ + $num_untracked \ + $num_stashed \ + $clean exit From 52bfba7d37218dbacb066bfef45ff76f9836db35 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 13 Oct 2015 18:31:49 +0200 Subject: [PATCH 68/69] Added documentation in Default theme --- themes/Default.bgptheme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 40c97ec..fd823cb 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -61,7 +61,12 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"; fi # indicator if the last command returned with an exit code of other than 0 - if [[ -z ${GIT_PROMPT_STATUS_COMMAND} ]]; then GIT_PROMPT_STATUS_COMMAND="gitstatus.sh"; fi # Point out the command to get the gitstatus from + # Possible to change which command is used to create git status information + # There are three options: + # 1) gitstatus.sh (uses git status --branch --porcelain - fast, requires git > 1.7.10) + # 2) gitstatus_pre-1.7.10.sh (Uses a variety of git commands and pipes - slower, works with older git clients) + # 3) gitstatus.py (Unsupported, lack features found in the bash versions) + if [[ -z ${GIT_PROMPT_STATUS_COMMAND} ]]; then GIT_PROMPT_STATUS_COMMAND="gitstatus.sh"; fi # Point out the command to get the git status from # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with From 67e7d6a08b03beb88ea028117babde9fd2c6379c Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 13 Oct 2015 18:43:44 +0200 Subject: [PATCH 69/69] Fixed bug where not all untracked files in folders were shown --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 9f345e5..95d312a 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -15,7 +15,7 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -gitstatus=$( LC_ALL=C git status --porcelain --branch ) +gitstatus=$( LC_ALL=C git status --untracked-files=all --porcelain --branch ) # if the status is fatal, exit now [[ "$?" -ne 0 ]] && exit 0