diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-10-05 01:10:00 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-10-05 01:48:45 +0900 |
commit | 8fa9e85980b8a7f291e5f749c93f11be7972a161 (patch) | |
tree | fda4f03c221019b2a27a1ea372a2c32433b35fa0 /shell/completion.bash | |
parent | 92a75c9563600a174e9ee8334853f99ed560492a (diff) |
[zsh-completion] Allow custom completion function
While in bash you can externally register custom completion functions
using `complete` command, it was not possible to do so in zsh without
changing completion.zsh as the name of the supported commands are
hard-coded within the code (See #362). With this commit, fzf-completion
of zsh will first look if `_fzf_COMMAND_completion` exists and calls the
function, so one can externally define completion functions for specific
commands.
This commit also tries to make the interface of (yet undocumented)
_fzf_list_completion helper function consistent across bash and zsh.
So the following code works both on bash and zsh.
_fzf_pass_completion() {
local pwdir=${PASSWORD_STORE_DIR-~/.password-store/}
local stringsize="${#pwdir}"
let "stringsize+=1"
_fzf_list_completion '+m' "$@" << "EOF"
find "$pwdir" -name "*.gpg" -print | cut -c "$stringsize"- | sed -e 's/\(.*\)\.gpg/\1/'
EOF
}
# Only on bash
complete -F _fzf_pass_completion -o default -o bashdefault pass
Note that the suggested convention and the interface are not yet final
and subject to change.
/cc @d4ndo
Diffstat (limited to 'shell/completion.bash')
-rw-r--r-- | shell/completion.bash | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/shell/completion.bash b/shell/completion.bash index d7fdf26e..3335a6a3 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -195,7 +195,7 @@ _fzf_kill_completion() { _fzf_telnet_completion() { _fzf_list_completion '+m' "$@" << "EOF" - \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u + \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u EOF } @@ -207,13 +207,13 @@ EOF _fzf_env_var_completion() { _fzf_list_completion '-m' "$@" << "EOF" - declare -xp | sed 's/=.*//' | sed 's/.* //' + declare -xp | sed 's/=.*//' | sed 's/.* //' EOF } _fzf_alias_completion() { _fzf_list_completion '-m' "$@" << "EOF" - alias | sed 's/=.*//' | sed 's/.* //' + alias | sed 's/=.*//' | sed 's/.* //' EOF } |