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

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

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 26, 2024, 01:08 UTC
Message-ID
<Zir-eeK0CZxVLhcR@tapette.crustytoothpaste.net>
In-Reply-To
<pull.1710.git.git.1714071592035.gitgitgadget@gmail.com>
On 2024-04-25 at 18:59:51, Thomas via GitGitGadget wrote:
Show 7 quoted lines
> From: Thomas Queiroz <thomasqueirozb@gmail.com>
> 
> Since GIT_PS1_SHOWUPSTREAM is a variable with space separated values and
> zsh for loops do no split by space by default, parsing of the options
> wasn't actually being done. The `-d' '` is a hacky solution that works
> in both bash and zsh. The correct way to do that in zsh would be do use
> read -rA and loop over the resulting array but -A isn't defined in bash.

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.

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.

I use the above syntax (minus the shell check) in my zsh prompt and can confirm it works as expected.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: Thomas via GitGitGadgetNext: Junio C Hamano
Message 2 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.