diff --git a/plugins/invoke/README.md b/plugins/invoke/README.md new file mode 100644 index 00000000..883c82d8 --- /dev/null +++ b/plugins/invoke/README.md @@ -0,0 +1,4 @@ +## git +**Maintainer:** [IvanMalison](https://github.com/IvanMalison) + +This plugin adds zsh completion for [invoke](https://github.com/pyinvoke/invoke) diff --git a/plugins/invoke/_invoke b/plugins/invoke/_invoke new file mode 100644 index 00000000..e0d1be88 --- /dev/null +++ b/plugins/invoke/_invoke @@ -0,0 +1,68 @@ +#compdef inv invoke + +typeset -A opt_args +local context state line + +function _invoke_subcommands { + LISTINGS=( $(invoke -l | tail -n+2 | sed 's/^ *//g' | while read line ; do _remove_docstrings "$line"; done;) ) + for subcommand_listing in $LISTINGS + do + local comma_separated="$(echo $subcommand_listing | tr -d ')\n' | tr '(' ',')" + local names="$(_echo_split $comma_separated ',')" + echo $names | tr '\n' ' ' + done +} + +function _remove_docstrings { + local delimiter_character=' ' + if echo $1 | grep ')' > /dev/null + then + delimiter_character=')' + fi + echo $1 | cut -d "$delimiter_character" -f 1 +} + +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"