From 3bf33843f025c5ea2a906763667b06242453087d Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Mon, 29 May 2023 20:39:24 -0400 Subject: [PATCH] Adding zshell autocomplete script --- pyinvoke/autocomplete.zsh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pyinvoke/autocomplete.zsh diff --git a/pyinvoke/autocomplete.zsh b/pyinvoke/autocomplete.zsh new file mode 100644 index 0000000..c038a92 --- /dev/null +++ b/pyinvoke/autocomplete.zsh @@ -0,0 +1,34 @@ +# Invoke tab-completion script to be sourced with the Z shell. +# Known to work on zsh 5.0.x, probably works on later 4.x releases as well (as +# it uses the older compctl completion system). + +_complete_invoke() { + # `words` contains the entire command string up til now (including + # program name). + # + # We hand it to Invoke so it can figure out the current context: spit back + # core options, task names, the current task's options, or some combo. + # + # Before doing so, we attempt to tease out any collection flag+arg so we + # can ensure it is applied correctly. + collection_arg='' + if [[ "${words}" =~ "(-c|--collection) [^ ]+" ]]; then + collection_arg=$MATCH + fi + # `reply` is the array of valid completions handed back to `compctl`. + # Use ${=...} to force whitespace splitting in expansion of + # $collection_arg + reply=( $(invoke ${=collection_arg} --complete -- ${words}) ) +} + + +# Tell shell builtin to use the above for completing our given binary name(s). +# * -K: use given function name to generate completions. +# * +: specifies 'alternative' completion, where options after the '+' are only +# used if the completion from the options before the '+' result in no matches. +# * -f: when function generates no results, use filenames. +# * positional args: program names to complete for. +compctl -K _complete_invoke + -f invoke inv + +# vim: set ft=sh : +