Skip to content

zsh: rework ZSH completion #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions completions/sub.zsh
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
if [[ ! -o interactive ]]; then
return
fi
#compdef sub

compctl -K _sub sub
# This completion file should be linked to a directory in ZSH fpath
# and named `_sub`.

_sub() {
local word words completions
read -cA words
word="${words[2]}"

if [ "${#words}" -eq 2 ]; then
completions="$(sub commands)"
else
completions="$(sub completions "${word}")"
fi

reply=("${(ps:\n:)completions}")
}
case $CURRENT in
2)
local cmds
local -a commands
cmds=$(sub commands)
commands=(${(ps:\n:)cmds})
_wanted command expl "sub command" compadd -a commands
;;
*)
local cmd subcmds
local -a commands
cmd=${words[2]}
subcmds=$(sub completions ${words[2,$(($CURRENT - 1))]})
commands=(${(ps:\n:)subcmds})
_wanted subcommand expl "sub $cmd subcommand" compadd -a commands
;;
esac