Re: [PATCH 6/8] git-prompt: add fallback for shells without $'...'
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 23, 2024, 20:25 UTC
- Message-ID
- <xmqqy15rzwi5.fsf@gitster.g>
- In-Reply-To
- <1c1b58e20cab6b4989b140282353073165f0067e.1721762306.git.gitgitgadget@gmail.com>
"Avi Halachmi (:avih) via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: "Avi Halachmi (:avih)" <avihpit@yahoo.com> > > $'...' is new in POSIX (2024), and some shells support it in recent > versions, while others have had it for decades (bash, zsh, ksh93).
I will not look at this series futher during the current development cycle that is about to conclude, but ...
Show 10 quoted lines
> +__git_SOH=$'\1' __git_STX=$'\2' __git_ESC=$'\33'
> +__git_LF=$'\n' __git_CRLF=$'\r\n'
> +
> +if [ $'\101' != A ]; then # fallback for shells without $'...'
> + __git_CRLF=$(printf "\r\n\1\2\33") # CR LF SOH STX ESC
> + __git_ESC=${__git_CRLF#????}; __git_CRLF=${__git_CRLF%?}
> + __git_STX=${__git_CRLF#???}; __git_CRLF=${__git_CRLF%?}
> + __git_SOH=${__git_CRLF#??}; __git_CRLF=${__git_CRLF%?}
> + __git_LF=${__git_CRLF#?}
> +fi... given that these are not used literally in-place but are always referred to by their __git_BYTE names, if we are making this script portable across shells to the same degree as other shell scripts following our coding guidelines, I would prefer to see it done without any "fallback".
$(printf '\r') would work with bash, zsh and ksh93, too, and one time assignment to these variables is not going to be performance critical. Just forbid use of $'\octal' notation in the coding guidelines document, and implement just one variant.
Perhaps we should spell more things out that you wrote in some of your proposed log messages more explicitly. I think these have been rules we have followed (grep for them in *.sh files outside contrib/) but I did not find mention in the guidelines document.
Thanks.
Documentation/CodingGuidelines | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines index 1d92b2da03..bb058fcc87 100644 --- c/Documentation/CodingGuidelines +++ w/Documentation/CodingGuidelines @@ -107,6 +107,8 @@ For shell scripts specifically (not exhaustive): - We do not use Process Substitution <(list) or >(list). + - We do not use Dollar-Single-Quotes $'<octal>' notation. + - Do not write control structures on a single line with semicolon. "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". @@ -140,7 +142,8 @@ For shell scripts specifically (not exhaustive): sort >actual && ... - - We prefer "test" over "[ ... ]". + - We prefer "test" over "[ ... ]". Never use "[[ ... ]]" unless in a + script only meant for bash. - We do not write the noiseword "function" in front of shell functions.