All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-prompt.sh: Omit prompt for ignored directories
@ 2014-10-08 19:04 Jess Austin
  2014-10-08 21:12 ` Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Jess Austin @ 2014-10-08 19:04 UTC (permalink / raw)
  To: git; +Cc: Jess Austin, szeder, rhansen

Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
tells __git_ps1 to display nothing when the current directory is
set (e.g. via .gitignore) to be ignored by git. In the absence of
GIT_PS1_OMITIGNORED this change has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
---
 contrib/completion/git-prompt.sh |  9 +++++++++
 t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c5473dc..6a26cb4 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,10 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED
+# to a nonempty value.
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -501,6 +505,11 @@ __git_ps1 ()
 	local f="$w$i$s$u"
 	local gitstring="$c$b${f:+$z$f}$r$p"
 
+	if [ -n "$(git check-ignore .)" ] && [ -n "${GIT_PS1_OMITIGNORED}" ]
+	then
+		printf_format=""
+	fi
+
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
 			gitstring=$(printf -- "$printf_format" "$gitstring")
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..55bcb6b 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >> .gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - prompt omitted in ignored directory' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_OMITIGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-01-14 11:45 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-08 19:04 [PATCH] git-prompt.sh: Omit prompt for ignored directories Jess Austin
2014-10-08 21:12 ` Richard Hansen
     [not found]   ` <CANp8Xb8ETG-ZFCqrOk=f-RbxtRxehBmAR1O5ozLH80zimWq_Gw@mail.gmail.com>
2014-10-08 21:37     ` Fwd: " Jess Austin
2014-10-09  5:37       ` Richard Hansen
2014-10-09 10:27         ` Jess Austin
2014-10-09 22:09           ` Richard Hansen
2014-10-14  2:32             ` [PATCH] git-prompt.sh: Hide prompt for ignored pwd Jess Austin
2014-10-14 18:47               ` Johannes Sixt
2014-10-14 19:08                 ` Richard Hansen
2014-10-14 19:21               ` Richard Hansen
2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
2014-10-15 20:28                   ` Richard Hansen
2015-01-05  7:03                     ` [PATCH v4] " Richard Hansen
2015-01-06 23:31                       ` Junio C Hamano
2015-01-07  1:22                         ` [PATCH v5 0/2] " Richard Hansen
2015-01-07  1:22                           ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt Richard Hansen
2015-01-14 11:45                             ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 SZEDER Gábor
2015-01-07  1:22                           ` [PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd Richard Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.