From c08e9eb2322d4b79771426f3c4d85010e07e1d5d Mon Sep 17 00:00:00 2001 From: Emilien T Date: Tue, 28 Jun 2022 11:46:44 +0200 Subject: [PATCH] Oh-My-Zsh plugin to support Taskfile.yml completion --- plugins/taskfile/README.md | 20 ++++++++++++++++++++ plugins/taskfile/_taskfile | 28 ++++++++++++++++++++++++++++ plugins/taskfile/taskfile.plugin.zsh | 1 + 3 files changed, 49 insertions(+) create mode 100644 plugins/taskfile/README.md create mode 100644 plugins/taskfile/_taskfile create mode 100644 plugins/taskfile/taskfile.plugin.zsh diff --git a/plugins/taskfile/README.md b/plugins/taskfile/README.md new file mode 100644 index 000000000..7de0ef2d3 --- /dev/null +++ b/plugins/taskfile/README.md @@ -0,0 +1,20 @@ +# `Taskfile` plugin + +This plugin provides completion for [Task](https://taskfile.dev/), as well as the shortcut alias `t` + +To use it add `taskfile` to the plugins array in your zshrc file. + +```bash +plugins=(... taskfile) +``` + +## Usage + +Of course, you need [Task](https://taskfile.dev/installation/) to be installed. + +Typing `t [TAB]` will give you a list of commands provided by your `Taskfile.yml` + +
+--- + +Thanks to [Berger91](https://github.com/Berger91/taskfile-zsh-autocompletion) for the original completion method. diff --git a/plugins/taskfile/_taskfile b/plugins/taskfile/_taskfile new file mode 100644 index 000000000..8aacd6db0 --- /dev/null +++ b/plugins/taskfile/_taskfile @@ -0,0 +1,28 @@ +#compdef task +local state line +declare -A opt_args + +_task_get_tasks () { + sed '1,/tasks:/d' Taskfile.yml | grep -iwE "^\ \ [a-z](.*)$" | sed 's/.$//' | awk '{ print $1 }' + while read included_task + do + taskfile_path=$(sed "1,/$included_task:/d" Taskfile.yml | grep -m 1 -iwE "^\ \ \ taskfile: .*$" | awk '{ print $2 }') + sed '1,/tasks:/d' $taskfile_path | grep -iwE "^\ \ [a-z](.*)$" | sed 's/.$//' | awk -v included_task="$included_task" '{ print included_task":"$1 }' + + done < <(sed '1,/includes:/d' Taskfile.yml | grep -iwE "^\ \ [a-z](.*)$" | sed 's/.$//' | awk '{ print $1 }') +} + +_taskfile () { + local state line + typeset -A opt_args + + _arguments \ + '*: :->args' + if [ -f Taskfile.yml ]; then + compadd `_task_get_tasks` + else + echo -e "\nNo taskfile found" + fi +} + +compdef _taskfile t=task diff --git a/plugins/taskfile/taskfile.plugin.zsh b/plugins/taskfile/taskfile.plugin.zsh new file mode 100644 index 000000000..038c8fa65 --- /dev/null +++ b/plugins/taskfile/taskfile.plugin.zsh @@ -0,0 +1 @@ +alias t=task