Skip to contentSkip to conversation

bash: Disable __git_ps1() if NO_GIT_PS1 is set

PATCH In review Øyvind A. Holm 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bash: Disable __git_ps1() if NO_GIT_PS1 is set

If the user works in a big repository on a slow USB disk or network drive, __git_ps1() can result in a significant delay before the prompt reappears. By setting the environment variable NO_GIT_PS1 to a nonempty value, the use of __git_ps1() is temporarily disabled.

---
 contrib/completion/git-completion.bash |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
contrib/completion/git-completion.bash +6 -0
index 0df356d..ee8cef5 100755
@@ -60,6 +60,11 @@
 #       per-repository basis by setting the bash.showUpstream config
 #       variable.
 #
+#       When working in a big repository on a slow USB disk or network
+#       drive, __git_ps1 may result in a noticeable delay before the prompt
+#       reappears.  To temporarily disable the use of __git_ps1, set
+#       NO_GIT_PS1 to a nonempty value.
+#
 #
 # To submit patches:
 #
@@ -225,6 +230,7 @@ __git_ps1_show_upstream ()
 # returns text to add to bash PS1 prompt (includes branch name)
 __git_ps1 ()
 {
+	[ -z "$NO_GIT_PS1" ] || return
 	local g="$(__gitdir)"
 	if [ -n "$g" ]; then
 		local r=""
Signature · 1 line
1.7.5.185.g0b9dee
#1 lore raw
Quoted 4 lines · Øyvind A. Holm

If the user works in a big repository on a slow USB disk or network drive, __git_ps1() can result in a significant delay before the prompt reappears. By setting the environment variable NO_GIT_PS1 to a nonempty value, the use of __git_ps1() is temporarily disabled.

As far as I can tell, the only thing that makes the prompt slow in large repositories is determining the dirty state; so instead of disabling the prompt entirely, you may want to just unset GIT_PS1_SHOWDIRTYSTATE. That way you still see which branch you are on, for example.

Signature · 3 lines
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/