Re: [PATCH v2 5/8] git-prompt: add some missing quotes

Junio C Hamano
2024-08-15T16:36:43Z

"Avi Halachmi (:avih) via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> In _command-arguments_, expanded/substituted values must be quoted:
> Good: [ "$mode" = yes ]; local s="*" x="$y" e="$?" z="$(cmd ...)"
> Bad: [ $mode = yes ]; local s=* x=$y e=$? z=$(cmd...)
>
> Still in _agumemts_, no need to quote non-expandable values:

arguments.

> - local bad_color=$c_red
> - local ok_color=$c_green
> + local bad_color="$c_red"
> + local ok_color="$c_green"
> local flags_color="$c_lblue"

Good. I think we in the past was burned by some shells that want to
see these assignments with "local" always quoted.

> # preserve exit status
> - local exit=$?
> + local exit="$?"
> local pcmode=no

Well no matter what value $? has, it by definition has a few digits
without any $IFS funnies. Does this really matter? I'd imagine
that we would prefer to treat "$?" exactly the same way as "no".

> @@ -379,7 +379,7 @@ __git_ps1 ()
> ;;
> 0|1) printf_format="${1:-$printf_format}"
> ;;
> - *) return $exit
> + *) return "$exit"
> ;;

Likewise.