Skip to content

Commit

Permalink
Revert "Support custom completions (#41)"
Browse files Browse the repository at this point in the history
This reverts commit 49702f7.
  • Loading branch information
Aloxaf committed Feb 28, 2020
1 parent 1a65f98 commit 191f6dc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,6 @@ Key Bindings:

For example <kbd>Ctrl</kdb>+<kdb>T</kbd> `bindkey '^T' toggle-fzf-tab`

### Custom completions

There exists mechanism for overwriting completion action for particular command
[similar to fzf](https://github.com/junegunn/fzf/wiki/Examples-(completion)).
If function named `_fzf_complete_foo` is found, it will be used for handling completions
of `foo` command.

If you also have [fzf's completions](https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh)
enabled (`completion.zsh` is sourced), you can use it's `_fzf_complete` helper function, for example:
```
_fzf_complete_foo() {
_fzf_complete "--multi --reverse" "$@" < <(
echo foo
echo bar
echo bazz
)
}
```

### Configure

Here are some variables which can be used to control the behavior of fzf-tab.
Expand Down Expand Up @@ -197,16 +178,6 @@ printc() {

The key trigger continuous completion. Default value: `/`

#### FZF_TAB_CUSTOM_COMPLETIONS

Whether to search for custom completion functions. Default value: `1`

#### FZF_TAB_CUSTOM_COMPLETIONS_PREFIX

Default value: `"_fzf_complete_"`

note: The default value matches fzf name convention so that the same functions can be used both by fzf and fzf-tab.

## Difference from other plugins

fzf-tab doesn't do "complete", it just shows your results of the default completion system.
Expand Down
26 changes: 1 addition & 25 deletions fzf-tab.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ _fzf_tab_remove_space() {
: ${FZF_TAB_SHOW_GROUP:=full}
: ${FZF_TAB_NO_GROUP_COLOR:=$'\033[37m'}
: ${FZF_TAB_CONTINUOUS_TRIGGER:='/'}
: ${FZF_TAB_CUSTOM_COMPLETIONS:='1'}
: ${FZF_TAB_CUSTOM_COMPLETIONS_PREFIX:='_fzf_complete_'}
: ${(A)=FZF_TAB_QUERY=prefix input first}
: ${(A)=FZF_TAB_SINGLE_GROUP=color header}
: ${(A)=FZF_TAB_GROUP_COLORS=\
Expand All @@ -97,7 +95,7 @@ _fzf_tab_remove_space() {

(( $+FZF_TAB_OPTS )) || FZF_TAB_OPTS=(
--ansi # Enable ANSI color support, necessary for showing groups
--expect='$FZF_TAB_CONTINUOUS_TRIGGER' # For continuous completion
--expect='$FZF_TAB_CONTINUOUS_TRIGGER' # For continuous completion
'--color=hl:$(( $#headers == 0 ? 108 : 255 ))'
--nth=2,3 --delimiter='\x00' # Don't search FZF_TAB_PREFIX
--layout=reverse --height='${FZF_TMUX_HEIGHT:=75%}'
Expand Down Expand Up @@ -308,29 +306,7 @@ _fzf_tab_complete() {

zle -C _fzf_tab_complete complete-word _fzf_tab_complete

# note: this function is called with user options
_fzf_tab_try_custom_completion() {
# do not steal fzf's completions
[[ $LBUFFER != *"${FZF_COMPLETION_TRIGGER-**}" ]] || return
local func prefix lbuf
() {
emulate -L zsh
local tokens=(${(z)LBUFFER})
func=${FZF_TAB_CUSTOM_COMPLETIONS_PREFIX}${tokens[1]}
(( $+functions[$func] )) || return
if [[ $LBUFFER == *' ' ]]; then
lbuf=$LBUFFER
else
prefix=$tokens[-1]
lbuf=${LBUFFER:0:-$#prefix}
fi
} || return
# must run with user options; don't add `emulate -L zsh` above this line
"$func" "$lbuf" || true
}

fzf-tab-complete() {
(( ! FZF_TAB_CUSTOM_COMPLETIONS )) || ! _fzf_tab_try_custom_completion || return 0
# complete or not complete, this is a question
# this name must be ugly to avoid clashes
local -i _fzf_tab_continue=1 _fzf_tab_should_complete=0
Expand Down

0 comments on commit 191f6dc

Please sign in to comment.