git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Hansen <rhansen@bbn.com>
To: Jess Austin <jess.austin@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd
Date: Tue, 14 Oct 2014 15:21:48 -0400	[thread overview]
Message-ID: <543D77CC.8060803@bbn.com> (raw)
In-Reply-To: <1413253924-8065-1-git-send-email-jess.austin@gmail.com>

On 2014-10-13 22:32, Jess Austin wrote:
> Set __git_ps1 to display nothing when present working directory is
> ignored, triggered by either the new environmental variable
> GIT_PS1_HIDE_ON_IGNORED_PWD or the new repository configuration
> variable bash.hideOnIgnoredPwd (or both). In the absence of these
> settings 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>
> ---
> On Thu, Oct 9, 2014 at 5:09 PM, Richard Hansen <rhansen@bbn.com> wrote:
>> On 2014-10-09 06:27, Jess Austin wrote:
>>> Would you want this configured in each repo (i.e. via a line in ".git/config"),
>>> or would you prefer something global so that it only need be set in one
>>> place? I'm not sure how the latter technique would work, so if that seems
>>> better please advise on how to go about that.
>>
>> A 'git config' variable is fine.  The bash.showDirtyState,
>> bash.showUntrackedFiles, and bash.showUpstream config variables seem
>> like good examples to follow.
> 
> I think this is what you meant. I changed the name of the envvar. Now the
> variables are GIT_PS1_HIDE_ON_IGNORED_PWD and bash.hideOnIgnoredPwd. I
> admit these are still kind of unwieldy, but maybe now they're more descriptive?

I do prefer the new names.  They are long, but how often will someone
have to type it?  In this case it's better to be descriptive than to be
short.  (I wonder if adding two letters would improve readability
further:  GIT_PS1_HIDE_WHEN_PWD_IGNORED and bash.hideWhenPwdIgnored.)

To avoid scaring people who might not want this feature enabled, I
recommend changing the subject line to something like this:

    git-prompt.sh: Option to hide prompt for ignored pwd

> 
> Please advise!
> 
> cheers,
> Jess
> 
>  contrib/completion/git-prompt.sh | 12 ++++++++++++
>  t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+)
> 
> 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.

As mentioned in my previous email, I would prefer the code to follow the
behavior of the other config variables (the environment variable has to
be set *and* the config variable has to be non-false).

>  
>  # 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 .)" ] &&

Rather than:

    [ -n "$(git check-ignore .)" ]

I would prefer:

    git check-ignore -q .

For example:

    if [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] &&
       [ "$(git config --bool bash.hideOnIgnoredPwd)" != "false" ] &&
       git check-ignore -q .
    then
            ...

-Richard


> +	   ( [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] ||
> +	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )
> +	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..a8ef8a3 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,44 @@ test_expect_success 'prompt - zsh color pc mode' '
>  	test_cmp expected "$actual"
>  '
>  
> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config disabled' '
> +	printf " (master)" >expected &&
> +	(
> +		cd ignored_dir &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config enabled' '
> +	printf "" >expected &&
> +	test_config bash.hideOnIgnoredPwd true &&
> +	(
> +		cd ignored_dir &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config disabled' '
> +	printf "" >expected &&
> +	(
> +		cd ignored_dir &&
> +		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config enabled' '
> +	printf "" >expected &&
> +	test_config bash.hideOnIgnoredPwd true &&
> +	(
> +		cd ignored_dir &&
> +		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
>  test_done
> 

      parent reply	other threads:[~2014-10-14 19:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-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
2014-10-14 19:21               ` Richard Hansen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=543D77CC.8060803@bbn.com \
    --to=rhansen@bbn.com \
    --cc=git@vger.kernel.org \
    --cc=jess.austin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).