git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Show presense of stashed changes in bash prompt.

From
DTDaniel Trstenjak <daniel.trstenjak@online.de>
Date
Jun 2, 2009, 18:03 UTC
Message-ID
<20090602180322.GA5719@laptop>
In-Reply-To
<20090602152915.GK30527@spearce.org>

Avoid the forgetting of stashed changes by showing them in the bash prompt.

If the presense is shown is configurable by setting GIT_PS1_SHOWSTASHSTATE to a nonempty value.

The code for checking if the stash has entries is taken from 'git-stash.sh'.

Signed-off-by: Daniel Trstenjak <daniel.trstenjak@online.de>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 98b9cbe..c4ae423 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -40,6 +40,10 @@
 #       with the bash.showDirtyState variable, which defaults to true
 #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
 #
+#       You can also see if currently something is stashed, by setting
+#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
+#       then a '$' will be shown next to the branch name. 
+#
 # To submit patches:
 #
 #    *) Read Documentation/SubmittingPatches
@@ -127,6 +131,7 @@ __git_ps1 ()
 
 		local w
 		local i
+		local s
 		local c
 
 		if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -148,12 +153,15 @@ __git_ps1 ()
 					fi
 				fi
 			fi
+			if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
+			        git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
+			fi
 		fi
 
 		if [ -n "${1-}" ]; then
-			printf "$1" "$c${b##refs/heads/}$w$i$r"
+			printf "$1" "$c${b##refs/heads/}$w$i$s$r"
 		else
-			printf " (%s)" "$c${b##refs/heads/}$w$i$r"
+			printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
 		fi
 	fi
 }
-- 
1.6.1.2
Previous: Shawn O. PearceNext: Jakub Narebski
Message 3 of 5 in “Show presense of stashed changes in bash prompt.”
  1. Show presense of stashed changes in bash prompt.Daniel Trstenjak, Jun 2, 2009
  2. Shawn O. PearceJun 2, 2009
  3. Daniel TrstenjakJun 2, 2009
  4. Jakub NarebskiJun 2, 2009
  5. Daniel TrstenjakJun 2, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.