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

Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd

From
RHRichard Hansen <rhansen@bbn.com>
Date
Oct 14, 2014, 19:08 UTC
Message-ID
<543D7497.2020001@bbn.com>
In-Reply-To
<543D6FD7.3090306@kdbg.org>
On 2014-10-14 14:47, Johannes Sixt wrote:
Show 28 quoted lines
> Am 14.10.2014 um 04:32 schrieb Jess Austin:
>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
>> index c5473dc..d7559ff 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_ON_IGNORED_PWD to a nonempty value, or set
>> +# bash.hideOnIgnoredPwd to true in the repository configuration.
>>  
>>  # check whether printf supports -v
>>  __git_printf_supports_v=
>> @@ -501,6 +506,13 @@ __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_HIDE_ON_IGNORED_PWD}" ] ||
>> +	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )
> 
> Ahem, no. Please do not punish users who are not interested in the new
> feature with two new processes every time __git_ps() is run. Think of
> Windows where fork() is really, *really* expensive.

Is this why bash.showDirtyState and friends aren't checked unless the corresponding environment variable is set to a non-empty value?

Regardless, it would be nice if the behavior matched the other bash.* variables (only check the bash.* variable if the corresponding environment variable is set, and default to true). The following should fix it:

    if [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] &&
       [ "$(git config --bool bash.hideOnIgnoredPwd)" != "false" ] &&
       [ "$(git check-ignore .)" ]
    then
            ...
-Richard
Show 14 quoted lines
> 
> BTW, you can write '{ foo || bar; }' to bracket a || chain without a
> sub-process.
> 
>> +	then
>> +		printf_format=""
>> +	fi
>> +
>>  	if [ $pcmode = yes ]; then
>>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>>  			gitstring=$(printf -- "$printf_format" "$gitstring")
> 
> -- Hannes
> 
Previous: Johannes SixtNext: Richard Hansen
Message 9 of 18 in “git-prompt.sh: Omit prompt for ignored directories”
  1. git-prompt.sh: Omit prompt for ignored directoriesJess Austin, Oct 8, 2014
  2. Richard HansenOct 8, 2014
  3. Fwd: [PATCH] git-prompt.sh: Omit prompt for ignored directoriesJess Austin, Oct 8, 2014
  4. Richard HansenOct 9, 2014
  5. Jess AustinOct 9, 2014
  6. Richard HansenOct 9, 2014
  7. git-prompt.sh: Hide prompt for ignored pwdJess Austin, Oct 14, 2014
  8. Johannes SixtOct 14, 2014
  9. Richard HansenOct 14, 2014
  10. Richard HansenOct 14, 2014
  11. git-prompt.sh: Option to hide prompt for ignored pwdJess Austin, Oct 15, 2014
  12. Richard HansenOct 15, 2014
  13. git-prompt.sh: Option to hide prompt for ignored pwdRichard Hansen, Jan 5, 2015
  14. Junio C HamanoJan 6, 2015
  15. 0/2 git-prompt.sh: Option to hide prompt for ignored pwdRichard Hansen, Jan 7, 2015
  16. 1/2 git-prompt.sh: if pc mode, immediately set PS1 to a plain promptRichard Hansen, Jan 7, 2015
  17. SZEDER GáborJan 14, 2015
  18. 2/2 git-prompt.sh: Option to hide prompt for ignored pwdRichard Hansen, Jan 7, 2015

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.