-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support FZF custom completion API #41
Conversation
fzf-tab.zsh
Outdated
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" | ||
} | ||
|
||
_fzf_feed_fifo() ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you copy functions over, give them a different name. Otherwise, when these functions get modified in fzf, the behavior of fzf-tab, and (worse!) of plain fzf will depend on the order in which files are sourced. It would be quite bad if fzf-tab affects the behavior of plan fzf.
Thanks for your contribution. But fzf-tab should be able to work together with fzf's completions.zsh, and its API is experimental. What's the advantage of supporting it? |
I will try to fix this
The ability to customize for particular commands is really cool. Actually It does not have to be fzf API, could be anything thet allow user to use zsh sources by default but provide convenient way to define custom behavior for for particular commands. Still, FZF mechanism for customization is quite convenient and easy to use and if user already defined some custom |
Doesn't Zsh have this feature out of the box? |
True. On the other hand, providing some framework/helper function like Consider for example: BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
_foo() {
for i in {1..40}; do
echo -e "${BLUE}foo${NC} completion$i"
done
}
_bar() {
# this is some slower command
sleep 1
for i in {40..80}; do
echo -e "${RED}bar${NC} completion$i"
done
}
_fzf_complete_foobar() {
_fzf_complete "--multi --ansi -n 2" "$@" < <(
_foo
_bar
)
}
_fzf_complete_foobar_post() { awk '{print $2}'; } How to easily write custom
I do not know zsh completion mechanism well, so after few minutes of reading some docs I started with something like:
From what I understand, using compdef mechanism it is hard to controll multi/no-multi and coloring, also completion is synchronous. |
I see. Streaming completions would definitely be useful. |
works together wit fzf completions now To enable, set |
Sorry I didn't make myself clear. |
No need for separate completion trigger. Currently, when one define some custom completion, one has to explicitly use fzf trigger ( Edit: |
Sounds great. Please update README.md as well. |
I cleaned up the PR and updated After some thought, I decided that the best solution is not providing |
@@ -306,7 +308,24 @@ _fzf_tab_complete() { | |||
|
|||
zle -C _fzf_tab_complete complete-word _fzf_tab_complete | |||
|
|||
_fzf_tab_try_custom_completion() { | |||
# do not steal fzf's completions | |||
[[ $LBUFFER =~ ${(q)FZF_COMPLETION_TRIGGER-'**'}$ ]] && return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set FZF_COMPLETION_TRIGGER=""
and bind fzf-completion
to a separate key (Ctrl-T). This way I can use TAB for normal completions and Ctrl-T to complete file arguments with fzf. I find that pressing Ctrl-T to complete file arguments with fzf is more convenient than pressing *-*-TAB.
With this setup _fzf_tab_try_custom_completion
always bails out early.
Does the check on the first line of _fzf_tab_try_custom_completion
presuppose that _fzf_tab_orig_widget
is fzf-completion
(or some other widget that respects FZF_COMPLETION_TRIGGER
)? I set _fzf_tab_orig_widget
to expand-or-complete
, so this check doesn't make much sense.
FWIW, I don't know what's the right thing to do here. I'm unsure how exactly I want completions to work. Just wanted to share that the current code is a bit odd and likely incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked for this configuration:
export FZF_COMPLETION_TRIGGER=""
bindkey '^T' fzf-completion
bindkey '^I' fzf-tab-complete
export fzf_default_completion=expand-or-complete
export _fzf_tab_orig_widget=expand-or-complete
If no custom completion function is defined, TAB triggers fzf-tab, ctrl-t triggers fzf.
If some custom completion function is defined, both TAB and ctrl-t triggers it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean it return 1 on the first if?
Yes.
If some custom completion function is defined, both TAB and ctrl-t triggers it.
Are you sure TAB triggers it? It doesn't for me. When I press TAB, _fzf_tab_try_custom_completion
returns on the first line, so _fzf_complete_*
is never called. Can you verify that _fzf_tab_orig_widget
is indeed expand-or-complete
in your setup?
API explained here, handy way of defining custom completions for particular commands.
Copied some functions from fzf
completions.zsh
to allow not sourcing it.