mollifier / cd-bookmark

zsh plugin to bookmark directories to cd.
MIT License
28 stars 3 forks source link

Bug: relative completion lists multiple duplicates of each item #9

Open erikw opened 3 years ago

erikw commented 3 years ago

Problem description

I just discovered the cool feature (27a8863051aff4fd87adff1eded289b490c92e0b) of relative completion. However it seems like there is also a bug: each completed relative path is listed multiple times for my bookmark home:

$ cd-bookmark -c home/<tab>
Applications/  Documents/     Movies/        Music/         Public/        dl/
Applications/  Documents/     Movies/        Pictures/      bak@           dl/
Applications/  Documents/     Movies/        Pictures/      bak@           dl/
Applications/  Documents/     Movies/        Pictures/      bak@           dl/
Applications/  Documents/     Movies/        Pictures/      bak@           dl/
Desktop/       Downloads/     Movies/        Pictures/      bak@           doc@
Desktop/       Downloads/     Music/         Pictures/      bak@           doc@
Desktop/       Downloads/     Music/         Public/        bak@           doc@
Desktop/       Downloads/     Music/         Public/        bin/           doc@
Desktop/       Library/       Music/         Public/        bin/           doc@
Desktop/       Library/       Music/         Public/        bin/           doc@
Desktop/       Library/       Music/         Public/        dl/            

Tested on zsh 5.8 on macOS 12.0.1.

Leads

With some debug printing I noticed that this function is called multiple times, maybe correlating with the numer of duplicates?

https://github.com/mollifier/cd-bookmark/blob/27a8863051aff4fd87adff1eded289b490c92e0b/_cd-bookmark#L57-L61

erikw commented 2 years ago

I have nailed it down now to that the bug occurs when using either or both of the _correct or _approximate completion function. Either of the settings below will trigger this behavior.

zstyle ':completion:*' menu select

# One of the lines below
zstyle ':completion:*' completer _complete _correct 
zstyle ':completion:*' completer _complete _approximate
zstyle ':completion:*' completer _complete _correct _approximate

but not for any other commands! Just cd-bookmark.

Update

A workaround is to disable menu select for cd-bookmark specifically. I tried also setting specific completer functions for cd-bookmark but this I could not get to work.

# Turn off menu completion for specifically cd-bookmark
zstyle ':completion:*:*:cd-bookmark:*' menu no

All in all, right now I'm having this config to avoid the bug

# Old config from before, unchanged
zstyle ':completion:*' menu select
zstyle ':completion:*' completer _complete _correct _approximate

# The workaround for this bug
zstyle ':completion:*:*:cd-bookmark:*' menu no