forked from colonelpanic/dotfiles
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
|
||||
local context state line
|
||||
|
||||
_invoke_subcommand () {
|
||||
if [ -f tasks.py ]; then
|
||||
local cache_policy
|
||||
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
|
||||
_arguments "*:invoke_command:->command"
|
||||
|
||||
if [[ -z "$cache_policy" ]]; then
|
||||
zstyle ":completion:${curcontext}:" cache-policy _invoke_subcommands_caching_policy
|
||||
fi
|
||||
case $state in
|
||||
(command)
|
||||
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 ) \
|
||||
&& ! _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
|
||||
return 0
|
||||
}
|
||||
|
||||
_invoke_subcommands_caching_policy() {
|
||||
local -a oldp
|
||||
oldp=( "$1"(Nmm+3) ) # 3min.
|
||||
(( $#oldp ))
|
||||
function _invoke_commands() {
|
||||
COMMAND_COMPLETIONS=( $(invoke -l |tr -d ' ' | tail -n+2 | sed '$ d' | tr '\n' ' ') )
|
||||
for COMPLETION in $COMMAND_COMPLETIONS
|
||||
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 \
|
||||
"--no-dedupe[Disable task deduplication.]" \
|
||||
"(-c --collection)"{-c,--collection}"[Specify collection name to load. May be given >1 time.]" \
|
||||
"(-e --echo)"{-e,--echo}"[Echo executed commands before running.]" \
|
||||
"(-h --help)"{-h,--help}"[Show core or per-task help and exit.]:command:_invoke_subcommand" \
|
||||
"(-H --hide)"{-H,--hide}"[Set default value of run()'s 'hide' kwarg.]:command:_invoke_subcommand" \
|
||||
"(-l --list)"{-l,--list}"[List available tasks.]" \
|
||||
"(-p --pty)"{-p,--pty}"[Use a pty when executing shell commands.]" \
|
||||
"(-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"
|
||||
function _echo_split () {
|
||||
local IFS
|
||||
IFS="$2" read -rA -- arr <<EOF
|
||||
$1
|
||||
EOF
|
||||
for i in "${arr[@]}"; do
|
||||
echo $i
|
||||
done
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user