{"thread":{"id":"36399","subject":"[PATCH] prompt: fix missing file errors in zsh","startedAt":"2014-04-11T23:32:25Z","lastAt":"2014-04-14T20:30:33Z","messageCount":2,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"238760","messageId":"1397259145-18514-1-git-send-email-felipe.contreras@gmail.com","threadId":"36399","inReplyTo":null,"subject":"[PATCH] prompt: fix missing file errors in zsh","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2014-04-11T23:32:25Z","receivedAt":"2014-04-11T23:32:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"zsh seems to have a bug while redirecting the stderr of the 'read'\ncommand:\n\n % read foo 2> /dev/null < foo\n zsh: no such file or directory: foo\n\nWhich causes errors to be displayed when certain files are missing.\nLet's add a convenience function to manually check if the file is\nreadable before calling \"read\".\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-prompt.sh | 21 ++++++++++++++-------\n 1 file changed, 14 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 7b732d2..1526086 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -259,6 +259,13 @@ __git_ps1_colorize_gitstring ()\n \tr=\"$c_clear$r\"\n }\n \n+eread ()\n+{\n+\tf=\"$1\"\n+\tshift\n+\ttest -r \"$f\" && read \"$@\" < \"$f\"\n+}\n+\n # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n # when called from PS1 using command substitution\n # in this mode it prints text to add to bash PS1 prompt (includes branch name)\n@@ -321,9 +328,9 @@ __git_ps1 ()\n \tlocal step=\"\"\n \tlocal total=\"\"\n \tif [ -d \"$g/rebase-merge\" ]; then\n-\t\tread b 2>/dev/null <\"$g/rebase-merge/head-name\"\n-\t\tread step 2>/dev/null <\"$g/rebase-merge/msgnum\"\n-\t\tread total 2>/dev/null <\"$g/rebase-merge/end\"\n+\t\teread \"$g/rebase-merge/head-name\" b\n+\t\teread \"$g/rebase-merge/msgnum\" step\n+\t\teread \"$g/rebase-merge/end\" total\n \t\tif [ -f \"$g/rebase-merge/interactive\" ]; then\n \t\t\tr=\"|REBASE-i\"\n \t\telse\n@@ -331,10 +338,10 @@ __git_ps1 ()\n \t\tfi\n \telse\n \t\tif [ -d \"$g/rebase-apply\" ]; then\n-\t\t\tread step 2>/dev/null <\"$g/rebase-apply/next\"\n-\t\t\tread total 2>/dev/null <\"$g/rebase-apply/last\"\n+\t\t\teread \"$g/rebase-apply/next\" step\n+\t\t\teread \"$g/rebase-apply/last\" total\n \t\t\tif [ -f \"$g/rebase-apply/rebasing\" ]; then\n-\t\t\t\tread b 2>/dev/null <\"$g/rebase-apply/head-name\"\n+\t\t\t\teread \"$g/rebase-apply/head-name\" b\n \t\t\t\tr=\"|REBASE\"\n \t\t\telif [ -f \"$g/rebase-apply/applying\" ]; then\n \t\t\t\tr=\"|AM\"\n@@ -358,7 +365,7 @@ __git_ps1 ()\n \t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n \t\telse\n \t\t\tlocal head=\"\"\n-\t\t\tif ! read head 2>/dev/null <\"$g/HEAD\"; then\n+\t\t\tif ! eread \"$g/HEAD\" head; then\n \t\t\t\tif [ $pcmode = yes ]; then\n \t\t\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n \t\t\t\tfi\n-- \n1.9.1+fc3.9.gc73078e\n"},{"id":"238864","messageId":"xmqqa9bnodqu.fsf@gitster.dls.corp.google.com","threadId":"36399","inReplyTo":"1397259145-18514-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] prompt: fix missing file errors in zsh","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-04-14T20:30:33Z","receivedAt":"2014-04-14T20:30:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> zsh seems to have a bug while redirecting the stderr of the 'read'\n> command:\n>\n>  % read foo 2> /dev/null < foo\n>  zsh: no such file or directory: foo\n>\n> Which causes errors to be displayed when certain files are missing.\n> Let's add a convenience function to manually check if the file is\n> readable before calling \"read\".\n\nOK.  I wondered if this can become conditional to zsh (with the\ncommon code still using eread, just the implementation of shell\nfunction being different from zsh and bash), but I doubt it would be\nworth it (other people can contradict me, of course).\n\nWill queue.  Thanks.\n\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-prompt.sh | 21 ++++++++++++++-------\n>  1 file changed, 14 insertions(+), 7 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 7b732d2..1526086 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -259,6 +259,13 @@ __git_ps1_colorize_gitstring ()\n>  \tr=\"$c_clear$r\"\n>  }\n>  \n> +eread ()\n> +{\n> +\tf=\"$1\"\n> +\tshift\n> +\ttest -r \"$f\" && read \"$@\" < \"$f\"\n> +}\n> +\n>  # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n>  # when called from PS1 using command substitution\n>  # in this mode it prints text to add to bash PS1 prompt (includes branch name)\n> @@ -321,9 +328,9 @@ __git_ps1 ()\n>  \tlocal step=\"\"\n>  \tlocal total=\"\"\n>  \tif [ -d \"$g/rebase-merge\" ]; then\n> -\t\tread b 2>/dev/null <\"$g/rebase-merge/head-name\"\n> -\t\tread step 2>/dev/null <\"$g/rebase-merge/msgnum\"\n> -\t\tread total 2>/dev/null <\"$g/rebase-merge/end\"\n> +\t\teread \"$g/rebase-merge/head-name\" b\n> +\t\teread \"$g/rebase-merge/msgnum\" step\n> +\t\teread \"$g/rebase-merge/end\" total\n>  \t\tif [ -f \"$g/rebase-merge/interactive\" ]; then\n>  \t\t\tr=\"|REBASE-i\"\n>  \t\telse\n> @@ -331,10 +338,10 @@ __git_ps1 ()\n>  \t\tfi\n>  \telse\n>  \t\tif [ -d \"$g/rebase-apply\" ]; then\n> -\t\t\tread step 2>/dev/null <\"$g/rebase-apply/next\"\n> -\t\t\tread total 2>/dev/null <\"$g/rebase-apply/last\"\n> +\t\t\teread \"$g/rebase-apply/next\" step\n> +\t\t\teread \"$g/rebase-apply/last\" total\n>  \t\t\tif [ -f \"$g/rebase-apply/rebasing\" ]; then\n> -\t\t\t\tread b 2>/dev/null <\"$g/rebase-apply/head-name\"\n> +\t\t\t\teread \"$g/rebase-apply/head-name\" b\n>  \t\t\t\tr=\"|REBASE\"\n>  \t\t\telif [ -f \"$g/rebase-apply/applying\" ]; then\n>  \t\t\t\tr=\"|AM\"\n> @@ -358,7 +365,7 @@ __git_ps1 ()\n>  \t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n>  \t\telse\n>  \t\t\tlocal head=\"\"\n> -\t\t\tif ! read head 2>/dev/null <\"$g/HEAD\"; then\n> +\t\t\tif ! eread \"$g/HEAD\" head; then\n>  \t\t\t\tif [ $pcmode = yes ]; then\n>  \t\t\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n>  \t\t\t\tfi\n"}]}