Re: [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- Jan 14, 2015, 11:45 UTC
- Message-ID
- <20150114124500.Horde.yfl7_QOVJQq0-zVzaAY52g6@webmail.informatik.kit.edu>
- In-Reply-To
- <1420593747-24110-2-git-send-email-rhansen@bbn.com>
Hi,
Quoting Richard Hansen <rhansen@bbn.com>:
Show 49 quoted lines
> At the beginning of __git_ps1, right after determining that the
> function is running in pc mode, set PS1 to a plain (undecorated)
> prompt. This makes it possible to simply return early without having
> to set PS1 if the prompt should not be decorated.
>
> Signed-off-by: Richard Hansen <rhansen@bbn.com>
> ---
> contrib/completion/git-prompt.sh | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh
> b/contrib/completion/git-prompt.sh
> index 729f769..b0de082 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -299,6 +299,10 @@ __git_ps1 ()
> ps1pc_start="$1"
> ps1pc_end="$2"
> printf_format="${3:-$printf_format}"
> + # set PS1 to a plain prompt so that we can
> + # simply return early if the prompt should not
> + # be decorated
> + PS1="$ps1pc_start$ps1pc_end"
> ;;
> 0|1) printf_format="${1:-$printf_format}"
> ;;
> @@ -350,10 +354,6 @@ __git_ps1 ()
> rev_parse_exit_code="$?"
>
> if [ -z "$repo_info" ]; then
> - if [ $pcmode = yes ]; then
> - #In PC mode PS1 always needs to be set
> - PS1="$ps1pc_start$ps1pc_end"
> - fi
> return
> fi
>
> @@ -412,9 +412,6 @@ __git_ps1 ()
> else
> local head=""
> if ! __git_eread "$g/HEAD" head; then
> - if [ $pcmode = yes ]; then
> - PS1="$ps1pc_start$ps1pc_end"
> - fi
> return
> fi
> # is it a symbolic ref?
> --
> 2.2.1As the one responsible for the last hunk I really like this change.
Thanks, Gábor