From fe6fcb6446f07609582e1044dc111841eaf3b8d3 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Thu, 13 Mar 2025 11:32:58 +0100 Subject: [PATCH 1/6] Add task autocompletion --- README.md | 41 +++++++++++++++++++++++++++++++++++------ bin/task | 37 +++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 20fd4d6..60e4877 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ Generate your own Taskfile at [taskfile.sh](https://taskfile.sh). - Easy to understand and maintain - Automatically generated list of available task -## How does it work? +# How does it work? Taskfiles are simple bash scripts, but an easy-to-read function format. There are some things that we need to explain for our Taskfile setup. It all starts with a `Taskfile`. Download your `Taskfile` from [taskfile.sh](https://taskfile.sh) and save it. Make sure the Taskfile is executable: `chmod +x ./Taskfile`. You can now run `./Taskfile` in your terminal. -### Tasks +## Tasks A task is defined by creating a function that starts with `task:`. This defines a task that can be triggered by running the `./Taskfile`. Right next to the task, you should add a task definition with two hashes. This will let the @@ -40,7 +40,7 @@ function task:example { ## Show some example text In a task you can call other functions, and run all tooling you desire. Now running `./Taskfile example` will execute the new task. -### Sections +## Sections To group multiple tasks, sections can be created in your Taskfile. A section is created by creating a comment line with a double hashtag like so: @@ -51,17 +51,46 @@ a double hashtag like so: Lines with only a single `#` will not appear as section in `task:help` and can be seen as plain comments. -### Help command +## Help command Running `./Taskfile help`, the `task:help` function is triggered. This task will list all available sections and tasks using the double `##` comments you've learned about above. Now it's clear how you can run any other task! -## Credits +# Auto-completion + +Autocompletion works when you use `zsh` with `oh-my-zsh`. Create the following file in your oh-my-zsh directory +`~/.oh-my-zsh/completions/_task.zsh`: + +```shell +#compdef task + +_task() { + local -a commands + local tasks=$(task comp_targets) + + while IFS= read -r line; do + if [[ -n "$line" ]]; then + commands+=("$line") + fi + done <<< "$tasks" + + _describe -t commands 'task commands' commands +} + +_task "$@" +``` + +Now after running `task shorthand`, your `task` commands will get autocompleted. + +**Note:** if your task name contains `:` characters, the autocomplete functionality will break. Replace the `:` +character in your task names to prevent this. + +# Credits This Taskfile setup is based on [Adrian Cooney's Taskfile](https://github.com/adriancooney/Taskfile) and is widely adopted by [Enrise](https://enrise.com) in our modified flavour. -## Contributors +# Contributors A big thanks to all the contributors of Taskfile! diff --git a/bin/task b/bin/task index 77af4c3..9a11dfa 100755 --- a/bin/task +++ b/bin/task @@ -10,19 +10,32 @@ RED=$(printf '\033[31m') RESET=$(printf '\033[0m') while [ -d $CURRENT_DIR ] && [ $CURRENT_DIR != '/' ]; do - if [ -f ./Taskfile ]; - then - ./Taskfile $@ - exit $? - elif [ -f ./Makefile ]; then - echo -e "${RED}Found a Makefile instead of a Taskfile...${RESET}\n" - make $@ + if [[ -e "${CURRENT_DIR}/Taskfile" ]]; then + TASKFILE="${CURRENT_DIR}/Taskfile" + break + fi + + if [[ -e "${CURRENT_DIR}/Makefile" ]]; then + echo -e "Found a ${RED}Makefile${RESET} instead of a Taskfile...\n" + make --directory=$CURRENT_DIR $@ exit $? - else - cd ../ - CURRENT_DIR=$(pwd) fi + + CURRENT_DIR=$(dirname $CURRENT_DIR) done -echo -e "${RED}ERROR: ${RESET}./Taskfile not found in the current or parent directories." -exit 1 +if [[ -z "$TASKFILE" ]]; then + echo -e "${RED}ERROR: ${RESET}./Taskfile not found in the current or parent directories." + exit 1 +fi + +if [[ $1 == 'comp_targets' ]]; then + awk 'BEGIN {FS = " { [#][#][ ]?"} /^function task([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ {printf "%s:%s\n", $1, $2}' \ + "$TASKFILE" \ + | sed -E 's/[#]{2,}[ ]*//g' \ + | sed -E 's/function task://g' + exit 1 +fi + +$TASKFILE $@ +exit $? From 0fd070c03a69ec3a93b4d628c52f0a4f124f6b17 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Thu, 13 Mar 2025 11:43:28 +0100 Subject: [PATCH 2/6] Clean up awk regex --- bin/task | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/task b/bin/task index 9a11dfa..acbad33 100755 --- a/bin/task +++ b/bin/task @@ -30,8 +30,7 @@ if [[ -z "$TASKFILE" ]]; then fi if [[ $1 == 'comp_targets' ]]; then - awk 'BEGIN {FS = " { [#][#][ ]?"} /^function task([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ {printf "%s:%s\n", $1, $2}' \ - "$TASKFILE" \ + awk 'BEGIN {FS = " { [#][#][ ]?"} /^function task:(.*)[#][#][ ]?/ {printf "%s:%s\n", $1, $2}' "$TASKFILE" \ | sed -E 's/[#]{2,}[ ]*//g' \ | sed -E 's/function task://g' exit 1 From 85fa62bda83e32c598516b7f41c553e48747073a Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Fri, 14 Mar 2025 11:51:06 +0100 Subject: [PATCH 3/6] Allow : characters in task function names for autocompletion --- bin/task | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/task b/bin/task index acbad33..c1ac852 100755 --- a/bin/task +++ b/bin/task @@ -30,9 +30,10 @@ if [[ -z "$TASKFILE" ]]; then fi if [[ $1 == 'comp_targets' ]]; then - awk 'BEGIN {FS = " { [#][#][ ]?"} /^function task:(.*)[#][#][ ]?/ {printf "%s:%s\n", $1, $2}' "$TASKFILE" \ + awk 'BEGIN {FS = " { [#][#][ ]?"} /^function task:(.*)[#][#][ ]?/ {gsub(/:/, "\\:", $1); printf "%s:%s\n", $1, $2}' \ + "$TASKFILE" \ | sed -E 's/[#]{2,}[ ]*//g' \ - | sed -E 's/function task://g' + | sed -E 's/function task\\://g' exit 1 fi From 1a92b5cde7f6e3d468638513fd2baa6cfbb3e719 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Fri, 14 Mar 2025 11:52:03 +0100 Subject: [PATCH 4/6] Remove no longer needed : disclaimer in the readme --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 60e4877..eef7334 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ using the double `##` comments you've learned about above. Now it's clear how yo # Auto-completion -Autocompletion works when you use `zsh` with `oh-my-zsh`. Create the following file in your oh-my-zsh directory +Autocompletion works when you use `zsh` and `oh-my-zsh`. Create the following file in your oh-my-zsh directory `~/.oh-my-zsh/completions/_task.zsh`: ```shell @@ -82,9 +82,6 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. -**Note:** if your task name contains `:` characters, the autocomplete functionality will break. Replace the `:` -character in your task names to prevent this. - # Credits This Taskfile setup is based on [Adrian Cooney's Taskfile](https://github.com/adriancooney/Taskfile) and is widely From 3881d185cfbd095763f0270eaa152b4c13d6b41f Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Sun, 16 Mar 2025 18:50:23 +0000 Subject: [PATCH 5/6] Keep the usage simple and plain --- Taskfile | 2 +- src/components/Generator/GeneredTaskfile/taskfile-base.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Taskfile b/Taskfile index 9fb9c6a..21ec706 100755 --- a/Taskfile +++ b/Taskfile @@ -130,7 +130,7 @@ function task:help { ## Show all available tasks {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\ sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\ sed -E "s/function task:*/ /g" - echo -e "\n${BLUE}Usage:${RESET} $0 ${YELLOW}${RESET} " + echo -e "\n${BLUE}Usage:${RESET} ./Taskfile ${YELLOW}${RESET} " } function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile diff --git a/src/components/Generator/GeneredTaskfile/taskfile-base.sh b/src/components/Generator/GeneredTaskfile/taskfile-base.sh index 925c5d3..beca5a7 100644 --- a/src/components/Generator/GeneredTaskfile/taskfile-base.sh +++ b/src/components/Generator/GeneredTaskfile/taskfile-base.sh @@ -58,7 +58,7 @@ function task:help { ## Show all available tasks {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\ sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\ sed -E "s/function task:*/ /g" - echo -e "\n${BLUE}Usage:${RESET} $0 ${YELLOW}${RESET} " + echo -e "\n${BLUE}Usage:${RESET} ./Taskfile ${YELLOW}${RESET} " } function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile From 970592bea58f8cb102bcc64d1477aa814d3b74ad Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Tue, 18 Mar 2025 11:23:00 +0100 Subject: [PATCH 6/6] Fix settings window shrinking --- src/components/Generator/generator.module.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Generator/generator.module.scss b/src/components/Generator/generator.module.scss index e17019e..448cd69 100644 --- a/src/components/Generator/generator.module.scss +++ b/src/components/Generator/generator.module.scss @@ -31,7 +31,6 @@ @include from(large) { width: 25rem; align-self: flex-start; - max-height: none; } }