Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix zsh ${(@)history} syntax does not work with ksh_arrays #3893

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

lincheney
Copy link
Contributor

@lincheney lincheney commented Jun 24, 2024

When setopt ksh_arrays in zsh, ${(@kv)history} gives only the first entry rather than all.

This is breaking the zsh control-r history widget to show only the latest history entry rather than all (which isn't very useful).

I have setopt ksh_arrays set in my zshrc.

I believe this is caused by https://github.com/junegunn/fzf/pull/3882/files#diff-c1d0c74baf2323d5dc27290b500868528b9a80be6a0844e998eefb2f9f6ab968R114
specifically the change from ${(kv)history[@]} to ${(@kv)history} does not seem to work when you have setopt ksh_arrays (it gives back only the one latest history entry).

This fixes it for me, but a potentially better fix could be to add something like emulate -LR zsh at the start of all widgets

When `setopt ksh_arrays` in zsh, `${(@KV)history}` gives only the first entry rather than all.
@LangLangBart
Copy link
Contributor

Thanks for the fix.

man zshexpn
         k      If name refers to an  associative  array,  substitute  the  keys
                (element  names)  rather  than the values of the elements.  Used
                with subscripts (including ordinary arrays),  force  indices  or
                keys to be substituted even if the subscript form refers to val-
                ues.  However, this flag may  not  be  combined  with  subscript
                ranges.   With  the KSH_ARRAYS option a subscript `[*]' or `[@]'
                is needed to operate on the whole array, as usual.

something like emulate -LR zsh at the start of all widgets

Seems to have been tried in the past1 but reverted. The commenter on the commit probably deleted their account, as their comment on the change of this commit is no longer visible.

Footnotes

  1. [zsh] emulate -L zsh to avoid issues with incompatible options · junegunn/fzf@3a6af27 · GitHub

@junegunn junegunn merged commit e9e0011 into junegunn:master Jun 24, 2024
5 checks passed
@junegunn
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants