From f779848b49e1f91acdb4713d07a2552965a213f1 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 3 Jan 2015 09:55:37 -0800 Subject: [PATCH] Add caching to invoke tab completion. --- dotfiles/lib/completions/_inv | 2 - dotfiles/lib/completions/_invoke | 72 +++++++++++++++++++------------- 2 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 dotfiles/lib/completions/_inv diff --git a/dotfiles/lib/completions/_inv b/dotfiles/lib/completions/_inv deleted file mode 100644 index 85a678a6..00000000 --- a/dotfiles/lib/completions/_inv +++ /dev/null @@ -1,2 +0,0 @@ -#compdef inv -compdef inv='invoke' \ No newline at end of file diff --git a/dotfiles/lib/completions/_invoke b/dotfiles/lib/completions/_invoke index b7e624b5..dbefa766 100644 --- a/dotfiles/lib/completions/_invoke +++ b/dotfiles/lib/completions/_invoke @@ -1,43 +1,59 @@ -#compdef invoke +#compdef inv invoke -_invoke() { - typeset -A opt_args - local context state line +typeset -A opt_args +local context state line - _arguments "*:invoke_command:->command" - - case $state in - (command) - COMMAND_COMPLETIONS=( $(_invoke_commands | tr '\n' ' ') ) - for COMPLETION in $COMMAND_COMPLETIONS - do - compadd $COMPLETION - done - ;; - esac - - return 0 -} - -function _invoke_commands() { +function _invoke_subcommands { 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 + echo $names | tr '\n' ' ' done } -function _echo_split () { +function _echo_split { local IFS IFS="$2" read -rA -- arr <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 command:_complete_invoke_subcommand"