All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Tony Finch <dot@dotat.at>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] git-prompt: preserve value of $? inside shell prompt
Date: Mon, 22 Dec 2014 11:58:41 -0800	[thread overview]
Message-ID: <xmqqsig78nim.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <alpine.LSU.2.00.1412221808110.2546@hermes-1.csi.cam.ac.uk> (Tony Finch's message of "Mon, 22 Dec 2014 18:09:25 +0000")

Tony Finch <dot@dotat.at> writes:

> If you have a prompt which displays the command exit status,
> __git_ps1 without this change corrupts it, although it has
> the correct value in the parent shell:
>
> 	~/src/git (master) 0 $ set | grep ^PS1
> 	PS1='\w$(__git_ps1) $? \$ '
> 	~/src/git (master) 0 $ false
> 	~/src/git (master) 0 $ echo $?
> 	1
> 	~/src/git (master) 0 $
>
> There is a slightly ugly workaround:
>
> 	~/src/git (master) 0 $ set | grep ^PS1
> 	PS1='\w$(x=$?; __git_ps1; exit $x) $? \$ '
> 	~/src/git (master) 0 $ false
> 	~/src/git (master) 1 $
>
> This change makes the workaround unnecessary.
>
> Signed-off-by: Tony Finch <dot@dotat.at>
> ---
>  contrib/completion/git-prompt.sh | 4 ++++
>  1 file changed, 4 insertions(+)
>
> I hope that explains it properly :-)

Yes.  I wouldn't have spent 20 minutes experimenting with various
hypothetical use cases if the above were there in the first place.

Thanks.  Will queue.

> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c5473dc..5fe69d0 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -288,6 +288,7 @@ __git_eread ()
>  # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
>  __git_ps1 ()
>  {
> +	local exit=$?
>  	local pcmode=no
>  	local detached=no
>  	local ps1pc_start='\u@\h:\w '
> @@ -511,4 +512,7 @@ __git_ps1 ()
>  	else
>  		printf -- "$printf_format" "$gitstring"
>  	fi
> +
> +	# preserve exit status
> +	return $exit
>  }

  reply	other threads:[~2014-12-22 19:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-22 14:30 [PATCH] git-prompt: preserve command exit status Tony Finch
2014-12-22 17:19 ` Junio C Hamano
2014-12-22 18:09   ` [PATCH v2] git-prompt: preserve value of $? inside shell prompt Tony Finch
2014-12-22 19:58     ` Junio C Hamano [this message]
2014-12-22 22:18       ` Tony Finch
2015-01-13 23:57     ` SZEDER Gábor
2015-01-14 10:05       ` Tony Finch
2015-01-14 10:06       ` [PATCH] git-prompt: preserve value of $? in all cases Tony Finch
2015-01-14 12:10         ` SZEDER Gábor

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=xmqqsig78nim.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=dot@dotat.at \
    --cc=git@vger.kernel.org \
    /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 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.