git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: fix zsh parsing $GIT_PS1_SHOWUPSTREAM

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 26, 2024, 05:39 UTC
Message-ID
<xmqqr0esbs3l.fsf@gitster.g>
In-Reply-To
<Zir-eeK0CZxVLhcR@tapette.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 8 quoted lines
> I wonder if it might actually be better to adjust the shell options when
> we call into __git_ps1.  We could write this like so:
>
> 	[ -z "${ZSH_VERSION-}" ] || setopt localoptions shwordsplit
>
> That will turn on shell word splitting for just that function (and the
> functions it calls), so the existing code will work fine and we won't
> tamper with the user's preferred shell options.
Nice.  I did
    $ git grep -e 'for [a-z0-9_]* in ' contrib/completion/

and wondered why other hits were OK. The completion one seems to have "emulate" all over the place to hide zsh-ness from functions it borrows from git-completion.bash, but git-prompt side seems to lack necessary "compatibility" stuff.

Show 5 quoted lines
> My concern is that changing the way we write the code here might result
> in someone unintentionally changing it back because it's less intuitive.
> By specifically asking zsh to use shell word splitting, we get
> consistent behaviour between bash and zsh, which is really what we want
> anyway.
Very well said.
> I use the above syntax (minus the shell check) in my zsh prompt and can
> confirm it works as expected.
Thanks.

By the way, I notice that the title of the patch talks about "completion", but this is about a prompt. It needs to be updated in a future iteration.

Previous: brian m. carlson
Message 3 of 3 in “completion: fix zsh parsing $GIT_PS1_SHOWUPSTREAM”
  1. completion: fix zsh parsing $GIT_PS1_SHOWUPSTREAMThomas via GitGitGadget, Apr 25, 2024
  2. brian m. carlsonApr 26, 2024
  3. Junio C HamanoApr 26, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.