Skip to content

Commit

Permalink
git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Richard Hansen authored and Junio C Hamano committed Jan 7, 2015
1 parent c5b9256 commit 76b4309
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
;;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 76b4309

Please sign in to comment.