Skip to content

Commit

Permalink
Merge branch 'fc/prompt-zsh-read-from-file'
Browse files Browse the repository at this point in the history
* fc/prompt-zsh-read-from-file:
  prompt: fix missing file errors in zsh
  • Loading branch information
gitster committed Apr 18, 2014
2 parents 3f0c02a + 59d3924 commit 427ed40
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions contrib/completion/git-prompt.sh
Expand Up @@ -259,6 +259,13 @@ __git_ps1_colorize_gitstring ()
r="$c_clear$r"
}

eread ()
{
f="$1"
shift
test -r "$f" && read "$@" <"$f"
}

# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
# in this mode it prints text to add to bash PS1 prompt (includes branch name)
Expand Down Expand Up @@ -321,20 +328,20 @@ __git_ps1 ()
local step=""
local total=""
if [ -d "$g/rebase-merge" ]; then
read b 2>/dev/null <"$g/rebase-merge/head-name"
read step 2>/dev/null <"$g/rebase-merge/msgnum"
read total 2>/dev/null <"$g/rebase-merge/end"
eread "$g/rebase-merge/head-name" b
eread "$g/rebase-merge/msgnum" step
eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
r="|REBASE-m"
fi
else
if [ -d "$g/rebase-apply" ]; then
read step 2>/dev/null <"$g/rebase-apply/next"
read total 2>/dev/null <"$g/rebase-apply/last"
eread "$g/rebase-apply/next" step
eread "$g/rebase-apply/last" total
if [ -f "$g/rebase-apply/rebasing" ]; then
read b 2>/dev/null <"$g/rebase-apply/head-name"
eread "$g/rebase-apply/head-name" b
r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM"
Expand All @@ -358,7 +365,7 @@ __git_ps1 ()
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
if ! read head 2>/dev/null <"$g/HEAD"; then
if ! eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi
Expand Down

0 comments on commit 427ed40

Please sign in to comment.