Skip to content

Commit

Permalink
Simplify zsh completion
Browse files Browse the repository at this point in the history
Completion file shouldn't be sourced. It should provide only completion
code (source of _command) for command. It's task for package manager or
user to put under $fpath.
  • Loading branch information
z0rc authored and meatballhat committed Apr 19, 2022
1 parent 7b2e609 commit f89647b
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions autocomplete/zsh_autocomplete
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
#compdef $PROG

_cli_zsh_autocomplete() {
local -a opts
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi

local -a opts
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi

if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
_files
fi

return
}

compdef _cli_zsh_autocomplete $PROG
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
_files
fi

0 comments on commit f89647b

Please sign in to comment.