From 485ee5f707c1ce4cc3f0a910cd5b5ad5372d979c Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Mon, 13 Oct 2014 13:07:50 -0400 Subject: [PATCH 1/6] Made it so people can use an env var (dirtysymb) to set a custom dirty symbol. --- prompt.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prompt.sh b/prompt.sh index 6a737b8..2ac3650 100644 --- a/prompt.sh +++ b/prompt.sh @@ -1,3 +1,7 @@ +# Users can set the dirtysymb env var in their .bash_profile, etc, +# or they can leave it unset and it will default to the '*'. +export dirtysymb=${dirtysymb:="*"}; + find_git_branch() { # Based on: http://stackoverflow.com/a/13003854/170413 local branch @@ -14,7 +18,7 @@ find_git_branch() { find_git_dirty() { local status=$(git status --porcelain 2> /dev/null) if [[ "$status" != "" ]]; then - git_dirty='*' + git_dirty=$dirtysymb else git_dirty='' fi From b6ad09a768e4ebd16216d90e6416156a5a20a248 Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Thu, 13 Oct 2016 11:35:19 -0400 Subject: [PATCH 2/6] Added documentation about using the option. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 936ca9d..275acad 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Edit your `~/.profile` or `~/.bash_profile` and add the following to the top: ```bash export GITAWAREPROMPT=~/.bash/git-aware-prompt source $GITAWAREPROMPT/main.sh -export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " +export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_stash$git_dirty\[$txtrst\]\$ " ``` Optionally, if you want a nice pretty prompt when using `sudo -s`, also add @@ -69,6 +69,8 @@ your `PS1` variable, and make sure the variable value is defined with double quotes. A set of color variables have also been set for you to use. For a list of available colors check `colors.sh`. +To show if the current branch as stashes associated with it add `$git_stash` to +your `PS1` variable. ## Updating From 192f11627a364263d23f99400c51a7a369c8485c Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Thu, 13 Oct 2016 11:35:43 -0400 Subject: [PATCH 3/6] Added ability to show if the current branch has any stashes associated with it. --- prompt.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/prompt.sh b/prompt.sh index 2ac3650..bdc19fe 100644 --- a/prompt.sh +++ b/prompt.sh @@ -2,17 +2,30 @@ # or they can leave it unset and it will default to the '*'. export dirtysymb=${dirtysymb:="*"}; +# Show that there is a stash for the current branch +export hasstash=${hasstash:="S"}; + find_git_branch() { # Based on: http://stackoverflow.com/a/13003854/170413 - local branch if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then if [[ "$branch" == "HEAD" ]]; then branch='detached*' fi git_branch="($branch)" + else git_branch="" fi + +} + +find_git_stash() { + local stash + if stash=$(git stash list 2>/dev/null | grep $branch 2> /dev/null); then + git_stash="[$hasstash]" + else + git_stash="" + fi } find_git_dirty() { @@ -24,11 +37,14 @@ find_git_dirty() { fi } -PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND" +PROMPT_COMMAND="find_git_branch; find_git_dirty; find_git_stash; $PROMPT_COMMAND" # Default Git enabled prompt with dirty state # export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " +# Default Git enabled prompt with dirty state & showing stashes that for the current branch +# export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty$git_stash\[$txtrst\]\$ " + # Another variant: # export PS1="\[$bldgrn\]\u@\h\[$txtrst\] \w \[$bldylw\]\$git_branch\[$txtcyn\]\$git_dirty\[$txtrst\]\$ " From f5574fe2a6ffd0e6f59ad80642612c3a1f9e5508 Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Thu, 13 Oct 2016 13:27:31 -0400 Subject: [PATCH 4/6] Fixed bug that was misreporting stash status. --- prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt.sh b/prompt.sh index bdc19fe..0029b23 100644 --- a/prompt.sh +++ b/prompt.sh @@ -21,7 +21,7 @@ find_git_branch() { find_git_stash() { local stash - if stash=$(git stash list 2>/dev/null | grep $branch 2> /dev/null); then + if stash=$(git stash list 2>/dev/null | grep "WIP on $branch" 2> /dev/null); then git_stash="[$hasstash]" else git_stash="" From 71e7cc7078dfaf84894d4ee18c756e783cc7a3d4 Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Thu, 13 Oct 2016 13:42:08 -0400 Subject: [PATCH 5/6] Modified to be more intelligent when determining if the branch has stashed changed. --- prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt.sh b/prompt.sh index 0029b23..9afcc76 100644 --- a/prompt.sh +++ b/prompt.sh @@ -21,7 +21,7 @@ find_git_branch() { find_git_stash() { local stash - if stash=$(git stash list 2>/dev/null | grep "WIP on $branch" 2> /dev/null); then + if stash=$(git stash list 2>/dev/null | cut -d: -f2 | grep "$branch" 2> /dev/null); then git_stash="[$hasstash]" else git_stash="" From 4ba748e9f774fbac91b038f4c6386db1ea691b08 Mon Sep 17 00:00:00 2001 From: Aaron Salvo Date: Fri, 2 Dec 2016 15:03:21 -0500 Subject: [PATCH 6/6] Reworked code to determine if a stash exists for the current branch. --- prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt.sh b/prompt.sh index 9afcc76..18c5fc9 100644 --- a/prompt.sh +++ b/prompt.sh @@ -21,7 +21,7 @@ find_git_branch() { find_git_stash() { local stash - if stash=$(git stash list 2>/dev/null | cut -d: -f2 | grep "$branch" 2> /dev/null); then + if [[ -n $(git stash list --grep-reflog="${branch}:" 2> /dev/null ) ]]; then git_stash="[$hasstash]" else git_stash=""