From 84cc5e57b0e5dc831b0b0db18452bd23e4abce29 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Wed, 18 Sep 2024 16:46:02 +0200 Subject: [PATCH] fix(completions): zsh and powershell completions (#1809) --- completion/zsh/_task | 56 +++++++++++++++++++---------------- website/docs/installation.mdx | 2 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/completion/zsh/_task b/completion/zsh/_task index 56f2736bf1..ddb888d77b 100755 --- a/completion/zsh/_task +++ b/completion/zsh/_task @@ -1,6 +1,5 @@ #compdef task - -local context state state_descr line +compdef _task task typeset -A opt_args _GO_TASK_COMPLETION_LIST_OPTION="${GO_TASK_COMPLETION_LIST_OPTION:---list-all}" @@ -39,26 +38,33 @@ function __task_list() { _describe 'Task to run' scripts } -_arguments \ - '(-C --concurrency)'{-C,--concurrency}'[limit number of concurrent tasks]: ' \ - '(-p --parallel)'{-p,--parallel}'[run command-line tasks in parallel]' \ - '(-f --force)'{-f,--force}'[run even if task is up-to-date]' \ - '(-c --color)'{-c,--color}'[colored output]' \ - '(-d --dir)'{-d,--dir}'[dir to run in]:execution dir:_dirs' \ - '(--dry)--dry[dry-run mode, compile and print tasks only]' \ - '(-o --output)'{-o,--output}'[set output style]:style:(interleaved group prefixed)' \ - '(--output-group-begin)--output-group-begin[message template before grouped output]:template text: ' \ - '(--output-group-end)--output-group-end[message template after grouped output]:template text: ' \ - '(-s --silent)'{-s,--silent}'[disable echoing]' \ - '(--status)--status[exit non-zero if supplied tasks not up-to-date]' \ - '(--summary)--summary[show summary\: field from tasks instead of running them]' \ - '(-t --taskfile)'{-t,--taskfile}'[specify a different taskfile]:taskfile:_files' \ - '(-v --verbose)'{-v,--verbose}'[verbose mode]' \ - '(-w --watch)'{-w,--watch}'[watch-mode for given tasks, re-run when inputs change]' \ - + '(operation)' \ - {-l,--list}'[list describable tasks]' \ - {-a,--list-all}'[list all tasks]' \ - {-i,--init}'[create new Taskfile.yml]' \ - '(-*)'{-h,--help}'[show help]' \ - '(-*)--version[show version and exit]' \ - '*: :__task_list' +_task() { + _arguments \ + '(-C --concurrency)'{-C,--concurrency}'[limit number of concurrent tasks]: ' \ + '(-p --parallel)'{-p,--parallel}'[run command-line tasks in parallel]' \ + '(-f --force)'{-f,--force}'[run even if task is up-to-date]' \ + '(-c --color)'{-c,--color}'[colored output]' \ + '(-d --dir)'{-d,--dir}'[dir to run in]:execution dir:_dirs' \ + '(--dry)--dry[dry-run mode, compile and print tasks only]' \ + '(-o --output)'{-o,--output}'[set output style]:style:(interleaved group prefixed)' \ + '(--output-group-begin)--output-group-begin[message template before grouped output]:template text: ' \ + '(--output-group-end)--output-group-end[message template after grouped output]:template text: ' \ + '(-s --silent)'{-s,--silent}'[disable echoing]' \ + '(--status)--status[exit non-zero if supplied tasks not up-to-date]' \ + '(--summary)--summary[show summary\: field from tasks instead of running them]' \ + '(-t --taskfile)'{-t,--taskfile}'[specify a different taskfile]:taskfile:_files' \ + '(-v --verbose)'{-v,--verbose}'[verbose mode]' \ + '(-w --watch)'{-w,--watch}'[watch-mode for given tasks, re-run when inputs change]' \ + + '(operation)' \ + {-l,--list}'[list describable tasks]' \ + {-a,--list-all}'[list all tasks]' \ + {-i,--init}'[create new Taskfile.yml]' \ + '(-*)'{-h,--help}'[show help]' \ + '(-*)--version[show version and exit]' \ + '*: :__task_list' +} + +# don't run the completion function when being source-ed or eval-ed +if [ "$funcstack[1]" = "_task" ]; then + _task "$@" +fi diff --git a/website/docs/installation.mdx b/website/docs/installation.mdx index d4b76f36ab..1e93bc8083 100644 --- a/website/docs/installation.mdx +++ b/website/docs/installation.mdx @@ -287,7 +287,7 @@ task --completion fish | source ```powershell title="$PROFILE\Microsoft.PowerShell_profile.ps1" -Invoke-Expression (&task --completion powershell) +Invoke-Expression (&task --completion powershell | Out-String) ```