From: Junio C Hamano <gitster@pobox•com>
To: Felipe Contreras <felipe.contreras@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH] prompt: fix missing file errors in zsh
Date: Mon, 14 Apr 2014 13:30:33 -0700 [thread overview]
Message-ID: <xmqqa9bnodqu.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1397259145-18514-1-git-send-email-felipe.contreras@gmail.com> (Felipe Contreras's message of "Fri, 11 Apr 2014 18:32:25 -0500")
Felipe Contreras <felipe.contreras@gmail•com> writes:
> zsh seems to have a bug while redirecting the stderr of the 'read'
> command:
>
> % read foo 2> /dev/null < foo
> zsh: no such file or directory: foo
>
> Which causes errors to be displayed when certain files are missing.
> Let's add a convenience function to manually check if the file is
> readable before calling "read".
OK. I wondered if this can become conditional to zsh (with the
common code still using eread, just the implementation of shell
function being different from zsh and bash), but I doubt it would be
worth it (other people can contradict me, of course).
Will queue. Thanks.
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail•com>
> ---
> contrib/completion/git-prompt.sh | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 7b732d2..1526086 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -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)
> @@ -321,9 +328,9 @@ __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
> @@ -331,10 +338,10 @@ __git_ps1 ()
> 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"
> @@ -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
prev parent reply other threads:[~2014-04-14 20:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 23:32 [PATCH] prompt: fix missing file errors in zsh Felipe Contreras
2014-04-14 20:30 ` Junio C Hamano [this message]
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=xmqqa9bnodqu.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=felipe.contreras@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox