ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.33k stars 519 forks source link

Conflict between zoxide, zsh-autocomplete, and fzf results in erroneous behavior #775

Closed argamanza closed 2 months ago

argamanza commented 3 months ago

Environment

Shell: zsh 5.9 OS: macOS 14.1

Tools & Versions: zoxide: 0.9.4 fzf: 0.48.1 (installed via brew) zsh-autocomplete: 23.07.13

Description

When using zoxide in conjunction with zsh-autocomplete and fzf, the expected behavior of navigating to directories sorted by frecency fails. Specifically, after initiating a directory search with z prefix<SPACE><TAB>, selecting a directory from the fzf menu, and pressing <ENTER>, the fzf menu reopens with the input "0n" instead of changing the directory.

Steps to Reproduce

  1. Configure .zshrc with the following setup:
    
    # Set up fzf key bindings and fuzzy completion
    eval "$(fzf --zsh)"

Initialize zsh-autocomplete

source /opt/homebrew/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh

Initialize zoxide

eval "$(zoxide init zsh)"

2. Type z `sometext<SPACE><TAB>` to invoke the fzf menu.
3. Select a directory and press `<ENTER>`.

### Expected Behavior
Upon selecting a directory from the fzf menu and pressing `<ENTER>`, the shell should navigate to the selected directory.

### Actual Behavior
After selecting a directory, pressing `<ENTER>` reopens the fzf menu with `0n` pre-filled, leading to an empty list. Exiting this state requires pressing `<ESCAPE>` three times or manually correcting the input.

### Additional Information
- When using zoxide on a directory prefix with only one possible completion it will paste the command 4 times and `cd` into it.
- This issue does not occur when zsh-autocomplete is not initialized in the .zshrc file.
- using `zi` works as expected, seems like the issue is with the `<TAB>` key press.
- I will attach a video demonstrating the described behavior.

### Attempts to Resolve
Using `autoload -U compinit; compinit` as demonstrated below, instead of the zsh-autocomplete initialization allows zoxide to function as expected but without the desired autocomplete features.

autoload -U compinit; compinit

Initialize zsh-autocomplete

source /opt/homebrew/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh

Initialize zoxide

eval "$(zoxide init zsh)"



## TL;DR
When using zoxide in conjunction with zsh-autocomplete, pressing `<TAB>` performs _some action_ 4 times which leads to erroneous behavior.

## Issue Demonstration
![CleanShot 2024-03-30 at 00 01 18](https://github.com/ajeetdsouza/zoxide/assets/9576019/68726c69-ab08-45ce-aeee-eeb5a2c8695c)
ashleybartlett commented 2 months ago

I think I found the issue, and my PR https://github.com/ajeetdsouza/zoxide/pull/785 I believe fixes it, if you want to give it a try

ajeetdsouza commented 2 months ago

This is merged and will be released with zoxide v0.9.5.