set -g TASKWARRIOR_MAX_PENDING_RANDOM_TASKS 42 function taskwarrior::due_count set -l due_count (task status:pending due.before:now count) if test $due_count -gt 0 echo "There are $due_count tasks due!" end end function taskwarrior::project_tasks set -l project (basename (git rev-parse --show-toplevel)) task +project:$project status:pending end function taskwarrior::project_tasks::tasksamurai set -l project (basename (git rev-parse --show-toplevel)) tasksamurai +project:$project status:pending end function taskwarrior::add::track if test (count $argv) -gt 0 task add priority:L +personal +track $argv else tasksamurai +track end end function _taskwarrior::set_import_export_tags if test (uname) = Darwin set -gx TASK_IMPORT_TAG work set -gx TASK_EXPORT_TAG personal else set -gx TASK_IMPORT_TAG personal set -gx TASK_EXPORT_TAG work end end function taskwarrior::is_personal_device test (uname) = Linux end function taskwarrior::random_count task status:pending +random -work count end function taskwarrior::random_slots_left set -l pending (taskwarrior::random_count) math $TASKWARRIOR_MAX_PENDING_RANDOM_TASKS - $pending end # Normalizes a comma-separated list of tags by trimming whitespace and printing each tag on a new line. function taskwarrior::normalize_tags set -l tags_csv "$argv[1]" set -l normalized for tag in (string split ',' -- "$tags_csv") set -l trimmed (string trim -- "$tag") if test -n "$trimmed" set -a normalized "$trimmed" end end printf '%s\n' $normalized end function taskwarrior::export::bd if test -d ~/Notes/Bulgarian # Export bulgarian dumi set -l outfile ~/Notes/Bulgarian/bd-(date +%s).txt task +bd status:pending export | jq -r '.[].description' >$outfile # Guard against "No tasks specified." when there is nothing to delete test (task +bd status:pending count) -gt 0; and yes | task +bd status:pending delete cat ~/Notes/Bulgarian/bd-*.txt | sort -u >~/Notes/Bulgarian/compact-(date +%s).tmp && rm ~/Notes/Bulgarian/bd-*.txt sort -u ~/Notes/Bulgarian/compact-*.tmp >~/Notes/Bulgarian/bd-compacted.txt && rm ~/Notes/Bulgarian/compact-*.tmp end end function taskwarrior::export::maybe set -l maybefile ~/Notes/random/Maybe.md if test -f $maybefile # Export all maybe project tags for tag in m may maybe task +$tag -random status:pending export | jq -r '.[] | "\(.project): \(.description)"' | sed 's/^/* /' >>$maybefile.tmp.1 # Guard against "No tasks specified." when there is nothing to delete test (task +$tag -random status:pending count) -gt 0; and yes | task +$tag -random status:pending delete end grep -F '* ' $maybefile >>$maybefile.tmp.1 echo "# Maybe (7)" >$maybefile.tmp.2 echo '' >>$maybefile.tmp.2 echo 'Thinks I maybe will do something about or maybe not' >>$maybefile.tmp.2 echo '' >>$maybefile.tmp.2 sort -u $maybefile.tmp.1 >>$maybefile.tmp.2 && mv $maybefile.tmp.2 $maybefile && rm $maybefile.tmp.1 end end function taskwarrior::export::wins set -l winsfile ~/Notes/random/Wins.md if test -f $winsfile # Export all wins tags for tag in win wins task +$tag -random status:pending export | jq -r '.[].description' | sed 's/^/* /' >>$winsfile.tmp.1 # Guard against "No tasks specified." when there is nothing to delete test (task +$tag -random status:pending count) -gt 0; and yes | task +$tag -random status:pending delete &>/dev/null end grep -F '* ' $winsfile >>$winsfile.tmp.1 echo "# wins (7)" >$winsfile.tmp.2 echo '' >>$winsfile.tmp.2 echo 'Wins I had' >>$winsfile.tmp.2 echo '' >>$winsfile.tmp.2 sort -u $winsfile.tmp.1 >>$winsfile.tmp.2 && mv $winsfile.tmp.2 $winsfile && rm $winsfile.tmp.1 end end # Exports all tasks tagged +$tag for both pending and completed status into # per-status .json files in $WORKTIME_DIR, then deletes the exported tasks. The # tag name doubles as the file label (tw--export--.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 ts $argv[2] for task_status in pending completed set -l count (task +$tag status:$task_status count) if test $count -eq 0 continue end 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