diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-20 10:55:58 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-20 10:55:58 +0300 |
| commit | 1a6323c0e6c865694266cfab24bc022a5eecb534 (patch) | |
| tree | 38d20d336b737dc371922b26855146df6a95d5b4 /fish | |
| parent | a64fdc14e4dae51200802f13530b6480c59a75ef (diff) | |
taskwarrior: DRY up export/import into symmetric label helpers
The export path passed a file_label argument that was always identical to the
tag (TASK_EXPORT_TAG/TASK_EXPORT_TAG, rocky/rocky), and the import path
duplicated the find | while read | import/rm block once per source. Collapse
both into a single 'list of labels' model:
- _taskwarrior::export_tag drops the redundant file_label; the tag name is the
file label.
- New _taskwarrior::import_label imports+removes all files for one label,
replacing the two copy-pasted blocks.
- export loops over [$TASK_EXPORT_TAG rocky]; import loops over
[$TASK_IMPORT_TAG (hostname)]. The rocky routing (export by tag name, import
by hostname match) is now explicit and symmetric.
Behaviour is unchanged; verified with a stubbed-task/hostname harness covering
the rocky host, a non-rocky host, and label isolation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'fish')
| -rw-r--r-- | fish/conf.d/taskwarrior.fish | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/fish/conf.d/taskwarrior.fish b/fish/conf.d/taskwarrior.fish index 1948629..d3ff34f 100644 --- a/fish/conf.d/taskwarrior.fish +++ b/fish/conf.d/taskwarrior.fish @@ -113,13 +113,13 @@ function taskwarrior::export::wins end # Exports all tasks tagged +$tag for both pending and completed status into -# per-status .json files named after $file_label, then deletes the exported -# tasks. $file_label drives the filename so the matching importer (which keys -# off either TASK_IMPORT_TAG or the hostname) can pick the files up later. +# per-status .json files in $WORKTIME_DIR, then deletes the exported tasks. The +# tag name doubles as the file label (tw-<tag>-export-<ts>-<status>.json) so the +# importer can match the files again by tag name or, for host-routed tags like +# "rocky", by hostname. See _taskwarrior::import_label for the matching side. function _taskwarrior::export_tag set -l tag $argv[1] - set -l file_label $argv[2] - set -l ts $argv[3] + set -l ts $argv[2] for task_status in pending completed set -l count (task +$tag status:$task_status count) @@ -128,23 +128,34 @@ function _taskwarrior::export_tag continue end - echo "Exporting $count $task_status tasks to $file_label" - task +$tag status:$task_status export >"$WORKTIME_DIR/tw-$file_label-export-$ts-$task_status.json" + echo "Exporting $count $task_status tasks tagged +$tag" + task +$tag status:$task_status export >"$WORKTIME_DIR/tw-$tag-export-$ts-$task_status.json" yes | task +$tag status:$task_status delete &>/dev/null end end +# Imports and removes every export file in $WORKTIME_DIR whose embedded label +# (the <label> in tw-<label>-export-*.json) matches $label. The label is either a +# tag name or a hostname. See _taskwarrior::export_tag for the producing side. +function _taskwarrior::import_label + set -l label $argv[1] + + find $WORKTIME_DIR -name "tw-$label-export-*.json" | while read -l import + task import $import + rm $import + end +end + function taskwarrior::export _taskwarrior::set_import_export_tags set -l ts (date +%s) - # Export the OS-specific work/personal tag under its own tag name. - _taskwarrior::export_tag $TASK_EXPORT_TAG $TASK_EXPORT_TAG $ts - - # Export everything tagged +rocky under the "rocky" file label so the rocky - # host imports them via the hostname-based import path. The +rocky export is - # independent of the work/personal handling and runs on every host. - _taskwarrior::export_tag rocky rocky $ts + # Export this host's outgoing work/personal tag plus the host-routed +rocky + # tasks. Each tag is exported under its own name as the file label; +rocky is + # exported on every host so the rocky VM can import it via its hostname. + for tag in $TASK_EXPORT_TAG rocky + _taskwarrior::export_tag $tag $ts + end taskwarrior::export::bd taskwarrior::export::maybe @@ -154,17 +165,12 @@ end function taskwarrior::import _taskwarrior::set_import_export_tags - find $WORKTIME_DIR -name "tw-$TASK_IMPORT_TAG-export-*.json" | while read -l import - task import $import - rm $import - end - - # Hostname-keyed exports are imported only on the matching host. The +rocky - # exports are written as tw-rocky-export-*.json, so this picks them up when - # the local hostname is "rocky". - find $WORKTIME_DIR -name "tw-(hostname)-export-*.json" | while read -l import - task import $import - rm $import + # Import files labelled with this host's incoming work/personal tag, plus + # files labelled with this host's name. The +rocky exports are labelled + # "rocky", so the rocky host imports them through the hostname match while + # other hosts leave them in place for the rocky VM to pick up. + for label in $TASK_IMPORT_TAG (hostname) + _taskwarrior::import_label $label end end |
