fzf-tab-completion
fzf-tab-completion copied to clipboard
Is it possible not to display the FZF until the common part is completed?
For example, if I press tab after the text apti
, ZSH without fzf-tab-completion will complete the command to aptitude
, which is already in my muscle memory. Using the plugin instead will show all the commands starting with apti
and I don't like this.
Is it possible not to display FZF until the common part is completed, only if I press tab a second time (apti
-> tab -> aptitude
-> tab -> FZF completion)?
I agree: this tool should non-interactively complete the common leading part and wait for complete the rest if there are more than one items.
I'm willing to take a PR to optionally enable this. The difficulty you are going to run into is that fzf loads as soon as there are >=2 matches available even before all matches are loaded (this lets you complete or cancel without having to wait until the very end in case the completion is slow), whereas to compute a common prefix you need all matches to have loaded, so logic would be quite different.
I had the same issue.
Maybe not the best workaround, what I did is trigger fzf completion only when the character before the cursor is not a letter or a digit.
This way if I do:
$ apti<TAB>
It completes aptitude
without using fzf, and if I do any of those:
$ kill <TAB>
$ cd /<TAB>
I still get the benefit of fzf completion.
To do so, I added these lines in my ~/.zshrc
, after the moment I loaded fzf-zsh-completions.sh
:
function smart_completion() {
if [[ "$LBUFFER" =~ [a-zA-Z0-9]$ ]]; then
_main_complete
else
fzf_completion
fi
}
zle -C fzf_completion complete-word smart_completion