From 0e72d37a807788b8f3bf1a87f7adb843de83f2c4 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Mon, 8 Dec 2014 22:45:31 -0800 Subject: [PATCH] tab completion for invoke. --- dotfiles/lib/completions/_invoke | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 dotfiles/lib/completions/_invoke diff --git a/dotfiles/lib/completions/_invoke b/dotfiles/lib/completions/_invoke new file mode 100644 index 00000000..9338584e --- /dev/null +++ b/dotfiles/lib/completions/_invoke @@ -0,0 +1,44 @@ +#compdef inv 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 + + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy _invoke_subcommands_caching_policy + fi + + 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 +} + +_invoke_subcommands_caching_policy() { + local -a oldp + oldp=( "$1"(Nmm+3) ) # 3min. + (( $#oldp )) +} + +_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"