Skip to content
Myr

[zsh-completion] Allow custom completion function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 92a75c9 · Browse files · 2 files+25 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−26 removed

  • other:+25 added−26 removed

2 files+25 added−26 removed

modified:shell/completion.bash+3 added-3 removed
193 unmodified lines
194}195196_fzf_telnet_completion() {197 _fzf_list_completion '+m' "$@" << "EOF"198 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u198 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u199EOF200}201202_fzf_ssh_completion() {
3 unmodified lines
206}207208_fzf_env_var_completion() {209 _fzf_list_completion '-m' "$@" << "EOF"210 declare -xp | sed 's/=.*//' | sed 's/.* //'210 declare -xp | sed 's/=.*//' | sed 's/.* //'211EOF212}213214_fzf_alias_completion() {215 _fzf_list_completion '-m' "$@" << "EOF"216 alias | sed 's/=.*//' | sed 's/.* //'216 alias | sed 's/=.*//' | sed 's/.* //'217EOF218}219220# fzf options
55 unmodified lines
modified:shell/completion.zsh+22 added-23 removed