Add invoke completion.
This commit is contained in:
parent
b85f4eb075
commit
04694a0d99
2
dotfiles/lib/completions/_inv
Normal file
2
dotfiles/lib/completions/_inv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#compdef inv
|
||||||
|
compdef inv='invoke'
|
@ -1,44 +1,43 @@
|
|||||||
#compdef inv invoke
|
#compdef invoke
|
||||||
|
|
||||||
|
_invoke() {
|
||||||
typeset -A opt_args
|
typeset -A opt_args
|
||||||
local context state line
|
local context state line
|
||||||
|
|
||||||
_invoke_subcommand () {
|
_arguments "*:invoke_command:->command"
|
||||||
if [ -f tasks.py ]; then
|
|
||||||
local cache_policy
|
|
||||||
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
|
|
||||||
|
|
||||||
if [[ -z "$cache_policy" ]]; then
|
case $state in
|
||||||
zstyle ":completion:${curcontext}:" cache-policy _invoke_subcommands_caching_policy
|
(command)
|
||||||
fi
|
COMMAND_COMPLETIONS=( $(_invoke_commands | tr '\n' ' ') )
|
||||||
|
for COMPLETION in $COMMAND_COMPLETIONS
|
||||||
|
do
|
||||||
|
compadd $COMPLETION
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if ( [[ ${+_invoke_subcommands} -eq 0 ]] || _cache_invalid invoke_subcommands ) \
|
return 0
|
||||||
&& ! _retrieve_cache invoke_subcommands; then
|
|
||||||
|
|
||||||
_invoke_subcommands=(${${(f)"$(inv -l | grep "^ [a-zA-Z]" | awk '{print $1}')"}})
|
|
||||||
_store_cache invoke_subcommands _invoke_subcommands
|
|
||||||
fi
|
|
||||||
|
|
||||||
local expl
|
|
||||||
_wanted invoke_subcommands expl 'invoke subcommands' compadd -a _invoke_subcommands
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_invoke_subcommands_caching_policy() {
|
function _invoke_commands() {
|
||||||
local -a oldp
|
COMMAND_COMPLETIONS=( $(invoke -l |tr -d ' ' | tail -n+2 | sed '$ d' | tr '\n' ' ') )
|
||||||
oldp=( "$1"(Nmm+3) ) # 3min.
|
for COMPLETION in $COMMAND_COMPLETIONS
|
||||||
(( $#oldp ))
|
do
|
||||||
|
local comma_separated="$(echo $COMPLETION | tr -d ')\n' | tr '(' ',')"
|
||||||
|
local names="$(_echo_split $comma_separated ',')"
|
||||||
|
for name in $names
|
||||||
|
do
|
||||||
|
echo $name
|
||||||
|
done
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
_arguments -s -S \
|
function _echo_split () {
|
||||||
"--no-dedupe[Disable task deduplication.]" \
|
local IFS
|
||||||
"(-c --collection)"{-c,--collection}"[Specify collection name to load. May be given >1 time.]" \
|
IFS="$2" read -rA -- arr <<EOF
|
||||||
"(-e --echo)"{-e,--echo}"[Echo executed commands before running.]" \
|
$1
|
||||||
"(-h --help)"{-h,--help}"[Show core or per-task help and exit.]:command:_invoke_subcommand" \
|
EOF
|
||||||
"(-H --hide)"{-H,--hide}"[Set default value of run()'s 'hide' kwarg.]:command:_invoke_subcommand" \
|
for i in "${arr[@]}"; do
|
||||||
"(-l --list)"{-l,--list}"[List available tasks.]" \
|
echo $i
|
||||||
"(-p --pty)"{-p,--pty}"[Use a pty when executing shell commands.]" \
|
done
|
||||||
"(-r --root)"{-r,--root}"[Change root directory used for finding task modules.]:directory:_directories" \
|
}
|
||||||
"(-V --version)"{-V,--version}"[Show version and exit.]:" \
|
|
||||||
"(-w --warn-only)"{-w,--warn-only}"[Warn, instead of failing, when shell commands fail.]" \
|
|
||||||
"*::invoke commands:_invoke_subcommand"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user