diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-18 07:28:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-18 07:28:39 +0300 |
| commit | 7449e07d87236af910650d3268cba1a90de4cefa (patch) | |
| tree | 786b256f06372278c9cb4079dc8d88411a7ec88d | |
| parent | abe75a4209f86b562ac3e711804713c9a4325443 (diff) | |
taskwarrior: avoid duplicate random tasks
Check picked random note descriptions against pending +random tasks
and retry up to 3 times before skipping the slot.
Amp-Thread-ID: https://ampcode.com/threads/T-019ed8f8-b1e8-7191-8e47-57244a6d0e44
Co-authored-by: Amp <amp@ampcode.com>
| -rw-r--r-- | fish/conf.d/taskwarrior.fish | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/fish/conf.d/taskwarrior.fish b/fish/conf.d/taskwarrior.fish index 603f0d8..d7f642e 100644 --- a/fish/conf.d/taskwarrior.fish +++ b/fish/conf.d/taskwarrior.fish @@ -298,9 +298,27 @@ function _taskwarrior::fill_random_slot return end - # Pick one entry at random and tag it with both +random and the source file tag - set -l entry $entries[(builtin random 1 (count $entries))] - set -l parsed (_taskwarrior::random_quote_parse_entry $entry) + # Descriptions of pending +random tasks, used to avoid creating duplicates + set -l existing (task status:pending +random export | jq -r '.[].description') + + # Pick a random entry, retrying if its description already exists as a + # pending +random task. Try at most 3 times; if all attempts collide we give up on this slot rather than looping forever (there may be nothing else to pick). + set -l parsed + for attempt in (seq 3) + set -l entry $entries[(builtin random 1 (count $entries))] + set -l candidate (_taskwarrior::random_quote_parse_entry $entry) + if not contains -- "$candidate[2]" $existing + set parsed $candidate + break + end + end + + # All attempts hit an already-pending task; skip adding for this slot + if test (count $parsed) -eq 0 + return + end + + # Tag the chosen entry with both +random and the source file tag set -l add_args --tag random --tag $file_tag test -n "$parsed[1]"; and set -a add_args --project $parsed[1] test (builtin random 1 10) -eq 1; and set -a add_args --tag work |
