fix(shell): sort todo next tasks by priority and filter completed

Filter active tasks using tuxedo JSON output and sort by priority then
task ID, ensuring `todo next` and `todo check-next` consistently operate
on the highest priority pending task.
This commit is contained in:
kiskaadee committed 2026-10-18 12:34:14 -05:00
1 parent 2b1f075617
commit 1b228bb467
1 file changed
+11 -2
+11 -2
View File
@@ -43,18 +43,27 @@ _todo_color() {
}' }'
} }
_todo_active_tasks() {
tuxedo --json ls 2>/dev/null | jq -r '
map(select(.done | not))
| sort_by([ (if .priority then 0 else 1 end), .priority, .n ])
| .[]
| "\(.n) \(.raw)"
' 2>/dev/null
}
todo() { todo() {
case "$1" in case "$1" in
# todo next [N] / todo n [N] -> show top N priority tasks (default: 1) # todo next [N] / todo n [N] -> show top N priority tasks (default: 1)
next|n) next|n)
shift shift
local count="${1:-1}" local count="${1:-1}"
tuxedo 2>/dev/null ls | head -n "$count" | _todo_color _todo_active_tasks | head -n "$count" | _todo_color
;; ;;
# todo check-next / todo do-next / todo dn -> complete top priority task # todo check-next / todo do-next / todo dn -> complete top priority task
check-next|do-next|dn) check-next|do-next|dn)
local top_task local top_task
top_task=$(tuxedo 2>/dev/null ls | head -n 1) top_task=$(_todo_active_tasks | head -n 1)
if [[ -n "$top_task" ]]; then if [[ -n "$top_task" ]]; then
local task_id local task_id
task_id=$(echo "$top_task" | awk '{print $1}') task_id=$(echo "$top_task" | awk '{print $1}')