junegunn / junegunn/fzf

Feature request: Allow conditional routing for custom fuzzy completion postprocessing functions

Open
#3,367 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
83k
Forks
2.9k
Avg merge
17h 8m
Merged PRs (30d)
10

Description

- [X] I have read through the manual page (`man fzf`)
- [X] I have the latest version of fzf
- [X] I have searched through the existing issues

## Info

- OS
- [ ] Linux
- [X] Mac OS X
- [ ] Windows
- [ ] Etc.
- Shell
- [ ] bash
- [X] zsh
- [ ] fish

Maybe this is already possible to do, but the current documentation is insufficient for understanding how to implement it.

[The wiki shows an example for how to implement a custom fuzzy completion function with some conditional routing](https://github.com/junegunn/fzf/wiki/Examples-(completion)#zsh-complete-git-co-for-example) (`_fzf_complete_git`). This is useful because it shows how you could, in theory, write a single function that provides different completions for many different subcommands. For example, `git checkout` versus `git cherry-pick`, the former presenting `git branch` output and the latter presenting `git cherry-pick` output from which to select. The example in the wiki already gives a good idea for how to implement this using `if`/`elif` string matching.

However, the postprocessing function that goes with that example (`_fzf_complete_git_post`) does not illustrate how to branch the postprocessing in the same way. For example, say I want the `git cherry-pick` to `cut` out just the commit sha column, whereas `git checkout` should just pass branch names through unchanged. I attempted to implement this myself, on the assumption that the input to the postprocessing function is the line selected through fuzzy completion, but I was completely guessing, and ultimately didn't succeed.

My point is that either the kind of conditional routing (to handle multiple commands) that is already possible in the "main" completion function should be made possible in the "post" function too, or else if it is already possible, the documentation should be updated to show how to implement it.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked wiki example for _fzf_complete_git and compare its conditional routing with _fzf_complete_git_post. Trace what input the postprocessing function receives, then determine whether conditional routing is supported; done means either the behavior works for checkout and cherry-pick or the documentation clearly explains the supported approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
zsh
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.