1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Create Interactive Picker For Set Of Subtasks as a Taskfile TIL

This commit is contained in:
jbranchaud
2025-12-31 12:33:50 -07:00
parent db26fc97c6
commit d980514bff
2 changed files with 76 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1714 TILs and counting..._
_1715 TILs and counting..._
See some of the other learning resources I work on:
@@ -1534,6 +1534,7 @@ If you've learned something here, support my efforts writing daily TILs by
### Taskfile
- [Create Interactive Picker For Set Of Subtasks](taskfile/create-interactive-picker-for-set-of-subtasks.md)
- [Run A Task If It Meets Criteria](taskfile/run-a-task-if-it-meets-criteria.md)
### tmux

View File

@@ -0,0 +1,74 @@
# Create Interactive Picker For Set Of Subtasks
For [my TIL repo](https://github.com/jbranchaud/til), I have a `Taskfile.yml`
that defines a set of `notes:*` tasks for interacting with a `NOTES.md` file
that lives in a private Git submodule.
I wanted to make it easier on myself to not have to remember all the different
`notes` subtasks, so I created a helper task to make it easy to see the options
and run one.
A summary of the Taskfile is shown below including the entirety of the `notes`
task. That task will parse a listing of the available tasks (via `task --list`
and some `sed` commands) and pass those to `fzf` to provide an interactive
picker of the available subtasks.
```yaml
tasks:
notes:
desc: Interactive picker for notes tasks
cmds:
- |
TASK=$(task --list | grep "^\* notes:" | sed 's/^\* notes://' | sed 's/\s\+/ - /' | fzf --prompt="Select notes task: " --height=40% --reverse) || true
if [ -n "$TASK" ]; then
TASK_NAME=$(echo "$TASK" | awk '{print $1}' | sed 's/:$//')
task notes:$TASK_NAME
fi
interactive: true
silent: true
notes:edit:
...
notes:sync:
...
notes:open:
...
notes:push:
...
notes:status:
...
notes:pull:
...
notes:diff:
...
notes:log:
...
```
Now I can run the `notes` task to get a summary and interactive picker that
looks like the following:
```sh
task notes
Select notes task:
9/9
> │ Interactive picker for notes tasks
diff: Show uncommitted changes in notes
edit: All-in-one edit, commit, and push notes
log: Show recent commit history for notes
open: Opens NOTES.md (syncs latest changes first) in default editor
pull: Pull latest changes (alias for sync)
push: Commit and push changes to notes submodule
status: Check status of notes submodule
sync: Sync latest changes from the notes submodule
```
It pulls in the subtask name and description. I can then use `fzf`'s navigation
and filtering to narrow down and select the task I want to run.