Skip to content

Commit 427ed40

Browse files
committed
Merge branch 'fc/prompt-zsh-read-from-file'
* fc/prompt-zsh-read-from-file: prompt: fix missing file errors in zsh
2 parents 3f0c02a + 59d3924 commit 427ed40

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

contrib/completion/git-prompt.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ __git_ps1_colorize_gitstring ()
259259
r="$c_clear$r"
260260
}
261261

262+
eread ()
263+
{
264+
f="$1"
265+
shift
266+
test -r "$f" && read "$@" <"$f"
267+
}
268+
262269
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
263270
# when called from PS1 using command substitution
264271
# in this mode it prints text to add to bash PS1 prompt (includes branch name)
@@ -321,20 +328,20 @@ __git_ps1 ()
321328
local step=""
322329
local total=""
323330
if [ -d "$g/rebase-merge" ]; then
324-
read b 2>/dev/null <"$g/rebase-merge/head-name"
325-
read step 2>/dev/null <"$g/rebase-merge/msgnum"
326-
read total 2>/dev/null <"$g/rebase-merge/end"
331+
eread "$g/rebase-merge/head-name" b
332+
eread "$g/rebase-merge/msgnum" step
333+
eread "$g/rebase-merge/end" total
327334
if [ -f "$g/rebase-merge/interactive" ]; then
328335
r="|REBASE-i"
329336
else
330337
r="|REBASE-m"
331338
fi
332339
else
333340
if [ -d "$g/rebase-apply" ]; then
334-
read step 2>/dev/null <"$g/rebase-apply/next"
335-
read total 2>/dev/null <"$g/rebase-apply/last"
341+
eread "$g/rebase-apply/next" step
342+
eread "$g/rebase-apply/last" total
336343
if [ -f "$g/rebase-apply/rebasing" ]; then
337-
read b 2>/dev/null <"$g/rebase-apply/head-name"
344+
eread "$g/rebase-apply/head-name" b
338345
r="|REBASE"
339346
elif [ -f "$g/rebase-apply/applying" ]; then
340347
r="|AM"
@@ -358,7 +365,7 @@ __git_ps1 ()
358365
b="$(git symbolic-ref HEAD 2>/dev/null)"
359366
else
360367
local head=""
361-
if ! read head 2>/dev/null <"$g/HEAD"; then
368+
if ! eread "$g/HEAD" head; then
362369
if [ $pcmode = yes ]; then
363370
PS1="$ps1pc_start$ps1pc_end"
364371
fi

0 commit comments

Comments
 (0)