From ae2aef79422c90c689ebbed65a7f750f65b303d3 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 19:48:38 +0200 Subject: [PATCH 1/5] Allow running help on/for other Taskfiles --- src/components/Generator/GeneredTaskfile/taskfile-base.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Generator/GeneredTaskfile/taskfile-base.sh b/src/components/Generator/GeneredTaskfile/taskfile-base.sh index c3f64dd..47c66fa 100644 --- a/src/components/Generator/GeneredTaskfile/taskfile-base.sh +++ b/src/components/Generator/GeneredTaskfile/taskfile-base.sh @@ -52,14 +52,16 @@ function title { echo -e "\n${BLUE}=>${RESET} $1\n" } +# shellcheck disable=SC2120 function task:help { ## Show all available tasks + TASKFILE_FILE=${1-$0} banner title "Available tasks" awk 'BEGIN {FS = " { [#][#][ ]?"} /^([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ \ - {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\ + {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' "$TASKFILE_FILE" |\ sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\ sed -E "s/function task:*/ /g" - echo -e "\n${BLUE}Usage:${RESET} ./Taskfile ${YELLOW}${RESET} " + echo -e "\n${BLUE}Usage:${RESET} $TASKFILE_FILE ${YELLOW}${RESET} " } function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile From f6f48ad140d321dacc03251c0180465b9b137c83 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 20:57:31 +0200 Subject: [PATCH 2/5] Document subTaskfiles --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eef7334..579c434 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,8 @@ Lines with only a single `#` will not appear as section in `task:help` and can b 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! -# Auto-completion +# Advanced +## Auto-completion 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`: @@ -82,6 +83,59 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. +## SubTaskfiles + +Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a +single Taskfile? SubTaskfiles might be for you! They allow you to divide your tasks across multiple files while still +(also) calling them from a single one. + +There are two flavours, but in both cases tasks from the subTaskfile are called "via" a task in the root Taskfile, +like this: `./Taskfile foo ` + +### Full SubTaskfile + +This flavour of subTaskfile is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might +be working on part as often as the whole project. + +In the main Taskfile you call the subTaskfile like any other script: +```shell +function task:foo { ## bar + ./path/to/subtaskfile/Taskfile "${@-help}" +} +``` + +The subTaskfile is just a regular Taskfile, including utilities like `task:help`, `file:ensure` and a line with `task:"${@-help}"` +at the bottom. + +### Lean SubTaskfile + +This flavour of subTaskfile cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a +group of tasks that can be logically grouped together, possibly because they are rarely used. + +In the main Taskfile: +```shell +function task:foo { ## bar + SUB_TASKFILE_DIR="./path/to/subtaskfile/" + + source "$SUB_TASKFILE_DIR/Taskfile" + + task:"${@-_help}" +} +``` + +The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: +```shell +# Files in the subTaskfile's directory need to be prefixed with $SUB_TASKFILE_DIR +function task:call-script { ## Call a script + "$SUB_TASKFILE_DIR/some-script.sh" +} + +# Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help` +function task:_help { ## Show all available tasks + task:help "$SUB_TASKFILE_DIR/Taskfile" +} +``` + # Credits This Taskfile setup is based on [Adrian Cooney's Taskfile](https://github.com/adriancooney/Taskfile) and is widely From 00ce5f0712c864d584df36f36aa8eba2868e6db3 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 21:09:27 +0200 Subject: [PATCH 3/5] Clarify naming of the two types --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 579c434..dd0ae6e 100644 --- a/README.md +++ b/README.md @@ -83,34 +83,34 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. -## SubTaskfiles +## Splitting Taskfiles Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a -single Taskfile? SubTaskfiles might be for you! They allow you to divide your tasks across multiple files while still -(also) calling them from a single one. +single Taskfile? Splitting your Taskfiles might be for you! This allows you to divide your tasks across multiple files +while still (also) calling them from a single one. -There are two flavours, but in both cases tasks from the subTaskfile are called "via" a task in the root Taskfile, +There are two types, but in both cases tasks from the secondary Taskfile are called "via" a task in the root Taskfile, like this: `./Taskfile foo ` -### Full SubTaskfile +### Remote Taskfile -This flavour of subTaskfile is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might -be working on part as often as the whole project. +This type is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might be working +in a subdirectory as often as on the project as a whole. -In the main Taskfile you call the subTaskfile like any other script: +In the main Taskfile you call the secondary like any other script: ```shell function task:foo { ## bar - ./path/to/subtaskfile/Taskfile "${@-help}" + ./path/to/secondary/Taskfile "${@-help}" } ``` -The subTaskfile is just a regular Taskfile, including utilities like `task:help`, `file:ensure` and a line with `task:"${@-help}"` -at the bottom. +The secondary is just a regular Taskfile, including utilities (semi) optional ones like `task:help`, `file:ensure` and +the required line with `task:"${@-help}"`at the bottom. -### Lean SubTaskfile +### SubTaskfile -This flavour of subTaskfile cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a -group of tasks that can be logically grouped together, possibly because they are rarely used. +This type cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a group of tasks +that can be logically grouped together, for specific tasks or because they are rarely used. In the main Taskfile: ```shell @@ -125,7 +125,7 @@ function task:foo { ## bar The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: ```shell -# Files in the subTaskfile's directory need to be prefixed with $SUB_TASKFILE_DIR +# When you use files in the subTaskfile's directory, you need prefix them with $SUB_TASKFILE_DIR function task:call-script { ## Call a script "$SUB_TASKFILE_DIR/some-script.sh" } From 1717560a13c27d5a81bc604e163a5a223607d4c9 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 23:55:07 +0200 Subject: [PATCH 4/5] Remove "Remote Taskfile" type and other findings from in-person review --- README.md | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index dd0ae6e..f0e186a 100644 --- a/README.md +++ b/README.md @@ -83,56 +83,47 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. -## Splitting Taskfiles +## SubTaskfiles Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a -single Taskfile? Splitting your Taskfiles might be for you! This allows you to divide your tasks across multiple files -while still (also) calling them from a single one. +single Taskfile? Splitting your Taskfile might be for you! Using SubTaskfiles allows you to divide your tasks across +multiple files while still calling them from a single one. Most useful for splitting off a group of tasks that can be +logically grouped together, like for specific use-cases or because they are rarely used. -There are two types, but in both cases tasks from the secondary Taskfile are called "via" a task in the root Taskfile, -like this: `./Taskfile foo ` +Example use-cases: git-hooks, frontend- / backend-specific tasks, tasks that fix (infrequently occurring) bugs, etc. -### Remote Taskfile +SubTaskfiles can't be run directly, but are always run "via" a task in the root Taskfile, like this: +`Usage: ./Taskfile foo ` -This type is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might be working -in a subdirectory as often as on the project as a whole. +### How -In the main Taskfile you call the secondary like any other script: +Put this in the root Taskfile: ```shell function task:foo { ## bar - ./path/to/secondary/Taskfile "${@-help}" -} -``` - -The secondary is just a regular Taskfile, including utilities (semi) optional ones like `task:help`, `file:ensure` and -the required line with `task:"${@-help}"`at the bottom. - -### SubTaskfile - -This type cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a group of tasks -that can be logically grouped together, for specific tasks or because they are rarely used. + SUBTASKFILE_DIR="./path/to/subtaskfile/" -In the main Taskfile: -```shell -function task:foo { ## bar - SUB_TASKFILE_DIR="./path/to/subtaskfile/" - - source "$SUB_TASKFILE_DIR/Taskfile" + source "$SUBTASKFILE_DIR/SubTaskfile" task:"${@-_help}" } + +# Optional: use proxy-tasks like this for tasks you want to run straight from the root Taskfile +function task:baz { ## Call `foo baz` directly + task:foo baz +} ``` -The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: +Give SubTaskfile the filename `SubTaskfile`. It needs to contain only the tasks and sections you think useful (while +still having access to stuff like `file:ensure` from the root Taskfile!), but it has a few notes: ```shell -# When you use files in the subTaskfile's directory, you need prefix them with $SUB_TASKFILE_DIR +# When you refer to files in the subTaskfile's directory, you need prefix them with $SUBTASKFILE_DIR function task:call-script { ## Call a script - "$SUB_TASKFILE_DIR/some-script.sh" + "$SUBTASKFILE_DIR/some-script.sh" } # Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help` function task:_help { ## Show all available tasks - task:help "$SUB_TASKFILE_DIR/Taskfile" + task:help "$SUBTASKFILE_DIR/SubTaskfile" } ``` From 2fadd343643ec60660a95ad9bd530e58c4aa5222 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Sat, 21 Feb 2026 00:28:35 +0100 Subject: [PATCH 5/5] General typo-fixes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0e186a..f7dfb9c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Taskfile ([taskfile.sh](https://taskfile.sh)) -A `./Taskfile` is a task runner in plain and easy [Bash](https://nl.wikipedia.org/wiki/Bash). It adds a list of +A `./Taskfile` is a task runner in plain and easy [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)). It adds a list of available tasks to your project. Generate your own Taskfile at [taskfile.sh](https://taskfile.sh). @@ -14,7 +14,7 @@ Generate your own Taskfile at [taskfile.sh](https://taskfile.sh). - Very easy to use - Automate your most common tasks (updating, starting, building, etc...) - Easy to understand and maintain -- Automatically generated list of available task +- Automatically generated list of available tasks # How does it work? @@ -136,4 +136,4 @@ adopted by [Enrise](https://enrise.com) in our modified flavour. A big thanks to all the contributors of Taskfile! -![contirubtor avatars](https://contrib.rocks/image?repo=enrise/taskfile) +![contributor avatars](https://contrib.rocks/image?repo=enrise/taskfile)