sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
16.98k stars 397 forks source link

Misbehavior if `zoxide` history length <= 2 #1819

Closed FreeHarry closed 1 month ago

FreeHarry commented 1 month ago

What system are you running Yazi on?

Linux X11

What terminal are you running Yazi in?

kitty

yazi --debug output

Yazi
    Version: 0.3.3 (Arch Linux 2024-09-05)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (Arch Linux 2024-09-05)

Emulator
    Emulator.via_env: ("xterm-kitty", "")
    Emulator.via_csi: Ok(Kitty)
    Emulator.detect : Kitty

Adapter
    Adapter.matches: Kitty

Desktop
    XDG_SESSION_TYPE           : Some("x11")
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0.0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/usr/bin/zsh")
    EDITOR             : None
    VISUAL             : None
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : tmux 3.5a
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: 2.2.3
    magick           : 7.1.1-39
    fzf              : 0.55.0
    fd               : 10.2.0
    rg               : 14.1.1
    chafa            : 1.14.2
    zoxide           : 0.9.6
    7z               : 17.05
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1

Did you try the latest nightly build to see if the problem got fixed?

No, and I'll explain why below

Describe the bug

If only one entry is in zoxide history, Yazi shows the message: No directory history in the database, check out the zoxide docs to set it up. Even if are two entries in the history, but one of it is the current working directory, the message appears.

I except that the history is show as soon as there is at least one entry in the history, also if the entry is the current working directory.

Unfortunately I had no possibility to try nightly build.

Minimal reproducer

Anything else?

No response

sxyazi commented 1 month ago

This is by design - Zoxide cannot trigger the interactive selector when there's only one history entry, which is a limitation of zoxide itself.

Since Yazi passes --exclude when calling the selector, Yazi also has to exclude the cwd from history to avoid the flicker caused by zoxide's execution failure due to only one history found.

https://github.com/sxyazi/yazi/blob/0e118b5b3a5baacf7fe62971e2bfe2b0ad972bab/yazi-plugin/preset/plugins/zoxide.lua#L62

FreeHarry commented 1 month ago

Hmm. On my linux machine zoxide has no problems if only one entry is in the history. It shows it perfectly in interaction with fzf. And if the history contains no entries it outputs just "zoxide: no match found". Is it os-dependent what you mentioned?

sxyazi commented 1 month ago

Oh, they fixed it in zoxide 0.9.5 (specifically in https://github.com/ajeetdsouza/zoxide/commit/dbe6f185cf62744a03c107bae1f6c546daa72fb2#diff-f1a262a75a15c046693e28608e526e2c3d73fa8266139cf692bd8f7a4aae522fL115, where they removed --select-1 for fzf)

But I can still reproduce it in zoxide 0.9.4:

screenshot-002076

Considering some users might still be using an older version of zoxide, let's keep this behavior for now.

FreeHarry commented 1 month ago

If you put the --exclude also here...

image

you can reduce the length comparision to 1...

image

Then it only shows the No directory history...-message if HIST_ENTRIES - CWD == 0. And in all other cases the history is shown correctly.

But I couldn't check this to the zoxide-0.9.4 version.

sxyazi commented 1 month ago

Yes, but that doesn't change the fact that we still need more than 2 (>= 3) history entries, if one of them is cwd itself, to open the interactive selector.

It just shifts the workload Yazi is doing over to zoxide, but it won't help with hacking to fix the interactive behavior of the old zoxide version.

sxyazi commented 1 month ago

I dug into it and found that zoxide offers a _ZO_FZF_OPTS environment variable, which lets you completely rewrite the fzf parameters to fix the behavior of older zoxide versions, and this env variable has been supported since 0.4.2, will create a PR for it later.

sxyazi commented 1 month ago

Please try https://github.com/sxyazi/yazi/pull/1822

FreeHarry commented 1 month ago

I tested it with nightly build on Win11. It works if history length > 0.

But if history length == 0, this message in yazi is shown... image

and on the command line this message... image

But I according to lua file, I think this message should be shown in yazi: No directory history found, check Zoxide's doc to set it up and restart Yazi

Or did I need something to configure before using it?

sxyazi commented 1 month ago

I can't reproduce it. Are you sure you renamed/deleted the db.zo history database file?

https://github.com/user-attachments/assets/8d1a1643-54aa-4719-89a4-5f8c5309cd6a

What's your zoxide version? Could you try debugging zoxide.lua a bit as per https://github.com/sxyazi/yazi/issues/1813#issuecomment-2427368115 and see if zoxide query returns the expected result on your system?

FreeHarry commented 4 weeks ago

I rechecked the new nightly build and it is working now. Maybe I did something wrong before.