diff options
author | Jess Austin <jess.austin@gmail.com> | 2015-01-06 20:22:27 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-01-07 10:30:30 -0800 |
commit | 0120b8c85c7a52b26ea7062fec349d178a4e0208 (patch) | |
tree | 240588564286b674cd164057738dbbb5d020002e /contrib/completion | |
parent | git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt (diff) | |
download | tgif-0120b8c85c7a52b26ea7062fec349d178a4e0208.tar.xz |
git-prompt.sh: allow to hide prompt for ignored pwd
Optionally set __git_ps1 to display nothing when present working
directory is ignored, triggered by the new environment variable
GIT_PS1_HIDE_IF_PWD_IGNORED. This environment variable may be
overridden on any repository by setting bash.hideIfPwdIgnored to
"false". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED 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>
Signed-off-by: Richard Hansen <rhansen@bbn.com>
Reviewed-by: Richard Hansen <rhansen@bbn.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/completion')
-rw-r--r-- | contrib/completion/git-prompt.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index b0de082202..75c3f0f4ea 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -84,6 +84,11 @@ # 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_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the +# repository level by setting bash.hideIfPwdIgnored to "false". # check whether printf supports -v __git_printf_supports_v= @@ -369,6 +374,14 @@ __git_ps1 () local inside_gitdir="${repo_info##*$'\n'}" local g="${repo_info%$'\n'*}" + if [ "true" = "$inside_worktree" ] && + [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] && + [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] && + git check-ignore -q . + then + return + fi + local r="" local b="" local step="" |