summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-03-11 18:29:39 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-03-11 18:32:35 +0900
commit50b7608f9d27c09093846e172f230d92b401f956 (patch)
treec3257ce2128ee0329c161f2e2b1da2191abb0ccd /README.md
parent7085e5b629dcc6eaef4205802f07979f535c8d5f (diff)
Change custom fuzzy completion API
To make it easier to write more complex fzf options. Although this does not break backward compatibility, users are encouraged to update their code accordingly. # Before _fzf_complete "FZF_ARG1 FZF_ARG2..." "$@" < <( # Print candidates ) # After _fzf_complete FZF_ARG1 FZF_ARG2... -- "$@" < <( # Print candidates )
Diffstat (limited to 'README.md')
-rw-r--r--README.md53
1 files changed, 52 insertions, 1 deletions
diff --git a/README.md b/README.md
index 669881b2..bfd85800 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ Table of Contents
* [Environment variables / Aliases](#environment-variables--aliases)
* [Settings](#settings)
* [Supported commands](#supported-commands)
+ * [Custom fuzzy completion](#custom-fuzzy-completion)
* [Vim plugin](#vim-plugin)
* [Advanced topics](#advanced-topics)
* [Performance](#performance)
@@ -414,7 +415,7 @@ _fzf_comprun() {
case "$command" in
cd) fzf "$@" --preview 'tree -C {} | head -200' ;;
- export|unset) fzf "$@" --preview "eval 'echo \$'{}" "$@" ;;
+ export|unset) fzf "$@" --preview "eval 'echo \$'{}" ;;
ssh) fzf "$@" --preview 'dig {}' ;;
*) fzf "$@" ;;
esac
@@ -433,6 +434,56 @@ _fzf_setup_completion path ag git kubectl
_fzf_setup_completion dir tree
```
+#### Custom fuzzy completion
+
+_**(Custom completion API is experimental and subject to change)**_
+
+For a command named _"COMMAND"_, define `_fzf_complete_COMMAND` function using
+`_fzf_complete` helper.
+
+```sh
+# Custom fuzzy completion for "doge" command
+# e.g. doge **<TAB>
+_fzf_complete_doge() {
+ _fzf_complete --multi --reverse --prompt="doge> " -- "$@" < <(
+ echo very
+ echo wow
+ echo such
+ echo doge
+ )
+}
+```
+
+- The arguments before `--` are the options to fzf.
+- After `--`, simply pass the original completion arguments unchanged (`"$@"`).
+- Then write a set of commands that generates the completion candidates and
+ feed its output to the function using process substitution (`< <(...)`).
+
+zsh will automatically pick up the function using the naming convention but in
+bash you have to manually associate the function with the command using
+`complete` command.
+
+```sh
+[ -n "$BASH" ] && complete -F _fzf_complete_doge -o default -o bashdefault doge
+```
+
+If you need to post-process the output from fzf, define
+`_fzf_complete_COMMAND_post` as follows.
+
+```sh
+_fzf_complete_foo() {
+ _fzf_complete --multi --reverse --header-lines=3 -- "$@" < <(
+ ls -al
+ )
+}
+
+_fzf_complete_foo_post() {
+ awk '{print $NF}'
+}
+
+[ -n "$BASH" ] && complete -F _fzf_complete_foo -o default -o bashdefault foo
+```
+
Vim plugin
----------