Custom fuzzy completion without using _fzf_complete
- Dominant language
- Go
- Stars
- 83k
- Forks
- 2.9k
- Avg merge
- 17h 8m
- Merged PRs (30d)
- 10
Description
### Checklist
- [x] I have read through the manual page (`man fzf`)
- [x] I have searched through the existing issues
- [ ] For bug reports, I have checked if the bug is reproducible in the latest version of fzf
### Output of `fzf --version`
0.66.1 (c1b259c0)
### OS
- [ ] Linux
- [x] macOS
- [ ] Windows
- [ ] Etc.
### Shell
- [ ] bash
- [x] zsh
- [ ] fish
### Problem / Steps to reproduce
I've read through https://github.com/junegunn/fzf/wiki/Examples-(completion)#examples and a few other issues around custom fzf completion functions (in particular https://github.com/junegunn/fzf/issues/3367)
I've also read through https://github.com/junegunn/fzf/blob/master/shell/completion.zsh to get a better understanding of how the completion functions work.
I'm trying to write a custom git completion, which has a few examples in the wiki, and GH issues. However, I'm trying to use https://github.com/junegunn/fzf-git.sh as the source for my completions. I'm currently trying to add a completion for `git add` that uses `_fzf_git_files` as the source. The problem is that it's already executing fzf, and `_fzf_complete` also executes fzf, while also handling updating `$LBUFFER`.
What I'd like is a function I can call with the results of a completion while still hooking into the existing `_fzf_complete_$CMD` mechanism for triggering completion. In the end, I _think_ that I just need a function that updates `$LBUFFER` with the matches returned from `_fzf_git_files`.
So here's what I've gotten so far, and I think it's right, but I'm honestly not entirely sure:
```zsh
_fzf_complete_git() {
local cmd=$1
local -a tokens
tokens=(${(z)cmd})
subcommand=${tokens[2]}
local matches
case "$subcommand" in
add|rm|reset|restore)
matches=$(_fzf_git_files)
;;
*)
eval "zle ${fzf_default_completion:-expand-or-complete}"
return
;;
esac
if [ -n "$matches" ]; then
LBUFFER="$cmd$matches"
fi
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with shell/completion.zsh and the referenced fzf-git.sh implementation, then trace how _fzf_complete_$CMD invokes completion and updates LBUFFER. Compare that flow with the proposed _fzf_complete_git function and determine whether the requested behavior belongs in the existing completion mechanism. Done means the git add-related completions can use _fzf_git_files without launching a second fzf and update the zsh buffer correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, zsh
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100