olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~23,000 clones by ~15,000 unique cloners as of Nov '24, and averaging ~60 Homebrew installs monthly since June 2023
https://zsh-abbr.olets.dev
Other
578 stars 20 forks source link

[Bug report] involuntary history filtering possible in combination with zsh-autosuggestions and v5.x #91

Closed hojerst closed 6 months ago

hojerst commented 1 year ago

Is there an existing issue for this?

Update the issue title

Expected Behavior

When using the arrow keys (up/down) the zsh history should be navigated one entry at a time. If you enter something before pressing up/down, the history is only displaying entries that start with the entered text. same is true when you select a history entry and type something before navigating further.

Actual Behavior

When using zsh-abbr v5.0.1 and zsh-autosuggestions v0.7.0 at the same time, the navigation seems the expected behaviour isn't applied anymore. Rather, the history behaves like it is assuming an edit of the command line for every entry. So on first up you will navigate to the last entry. on next up the history is searched for everything beginning with the current prompt and so on. this essentially breaks the history function of zsh.

Steps To Reproduce

  1. install zsh-abbr v5.0.1 and zsh-autosuggestions v0.7.0
  2. enter ls -AlF
  3. enter echo hello
  4. enter ls
  5. press up key -> navigates to ls
  6. press up key -> navigates to ls -AlF

Environment

zsh-abbr version 5.0.1
zsh 5.9 (x86_64-apple-darwin22.0)
OSTYPE darwin22.0

Installation method

Manual

Installation method details

direct source of the plugin files

https://gitlab.com/hojerst/dotfiles/-/blob/main/.config/zsh/.zshrc#L77-96

Anything else?

This is a new behaviour of v5.x. Version 4 worked just fine. zsh-autosuggestions wasn't changed at all.

TBH I don't know if this is actually a bug of zsh-abbr or zsh-autosuggestions or even a weird side effect of combining both. Nevertheless, I just wanted to let you know. :)

olets commented 1 year ago

Thanks for the report!

I can't replicate the bug.

This (as you may know) is called history substring search. Nothing about zsh-abbr or zsh-autosuggestions should give you history substring searching. (I use zsh-abbr and zsh-autosuggestions, and to get history substring searching I additionally use zsh-history-substring-search.) But maybe one of them is!

To test the zsh-abbr v5 idea, you can try temporarily downgrading to 4.x. https://zsh-abbr.olets.dev/migrating-between-versions.html#downgrading-v5-to-v4

Looking briefly at your dotfiles, I think zsh-fzf-history-search is a likely suspect. I don't use fzf but my impression is substring matching is one of its selling points. Based on that impression, I'd expect an fzf history search plugin to perform substring history searches. Have you tried removing zsh-fzf-history-search?

OMZ also ships with an optional history substring search plugin. I think that plugin isn't enabled in your config, but it's worth double checking.

hojerst commented 1 year ago

I will have look at your suggestions. In the meantime, if you want to play around a "well known bad environment":

docker run --rm -it hojerst/shell@sha256:efd73cbe8118e5c99710c3d1af87e579087ed5ef0dc2b32a8db90e10f0633479

all i see is as soon as i upgraded from v4.8.1 to v5.0.1 this behaviour appeared: https://gitlab.com/hojerst/dotfiles/-/commits/main?ref_type=heads

Commit 399da6dfa72454f79c94c07b99a58a132f985ad2 in my dotfiles worked fine Commit b52877539dbe22da963e3f94b279284868d42913 in my dorfiles introduced the bug/weirdness (this commit only updates zsh-abbr from v4.8.1 to v5.0.1)

you can even play around with it in the above docker container:

# first commit broken
yadm checkout b52877539dbe22da963e3f94b279284868d42913
exec zsh

# commit before the upgrade worked fine
yadm checkout 399da6dfa72454f79c94c07b99a58a132f985ad2
exec zsh
olets commented 1 year ago

Reproduction in docker is A+++ bug reporting!

I misunderstood the report. So the first up arrow goes to the last command in history, and subsequent up arrows do history substring search based on that last command in history.

Confirmed the behavior and that the only change is the zsh-abbr upgrade, and that removing either zsh-autosuggestions or zsh-abbr resolves it.

I've pushed up a new branch for debugging this. Try switching zsh-abbr to the branch issues/91 (I'm not a yadm user and don't know how best to do that). That won't be a fix —now zsh-autosuggestions won't work as well if at all— but at least it will help us pin down the problem.

ShangjinTang commented 1 year ago

Hello, I think I am facing the saming issue. And now I am using v4.9.2 for resolving this issue temporarily.

[OS] ArchLinux x86_64 [Plugins] I have installed zsh-abbr and zsh-autosuggestions. [Issue] Keep pressing up arrow in shell, cannot show all histories. [More info] The issue exists on zsh-abbr v4.9.3 and afterwards version. v4.9.2 works fine. (ArchLinux x86_64)

olets commented 1 year ago

Thanks for the report @ShangjinTang!

I think I am facing the saming issue

Does this describe your problem? (from my comment above)

the first up arrow goes to the last command in history, and subsequent up arrows do history substring search based on that last command in history.

ShangjinTang commented 1 year ago

the first up arrow goes to the last command in history, and subsequent up arrows do history substring search based on that last command in history.

Yes, this is same as my issue.

On Ubuntu 22.04, I rollback to v4.8.2 as version >= v4.8.3 have this issue.

olets commented 6 months ago

Has anyone tried

Try switching zsh-abbr to the branch issues/91 (I'm not a yadm user and don't know how best to do that). That won't be a fix —now zsh-autosuggestions won't work as well if at all— but at least it will help us pin down the problem.

? Instructions for how to do it myself are welcome too.

hojerst commented 6 months ago

Hi sorry, for not coming back to you earlier. I basically just dropped zsh-autosuggestions in my setup and ignored the problem.

Anyway, I setup a small container image to reproduce/debug the issue: https://github.com/hojerst/zsh-abbr-issue-91/

see README there for instructions.

Also during building this, I learned that this seems to be a weird interaction between oh-my-zsh, zsh-autosuggestions and zsh-abbr. Remove any of those components and the issue disappears. It doesn't make debugging easier... The bug also dissapears when using zsh-abbr v4.8.1 as mentioned above.

olets commented 6 months ago

Fix released in v5.8.0. Excited to close this one out!

@hojerst I'm up for adding "bug reporting" and/or "user testing" to your listing in https://zsh-abbr.olets.dev/community/ and https://github.com/olets/zsh-abbr#community if you'd like. Lmk.

hojerst commented 6 months ago

Thanks for fixing the bug! And sure, feel free to update my contributions. I'm not here for the fame, though ;)

olets commented 6 months ago

@all-contributors please add @hojerst for bug and userTesting.

hojerst I forgot to say: thanks very much for that docker repo. I'm sure I'll use that model for testing zsh bugs in the future!