diff --git a/.config/i3blocks/taskwarrior b/.config/i3blocks/taskwarrior new file mode 100755 index 0000000..b3674e5 --- /dev/null +++ b/.config/i3blocks/taskwarrior @@ -0,0 +1,30 @@ +#!/bin/bash +set -euo pipefail + +source "${HOME}/bin/script_framework.sh" + +function colorized() { + echo "$2" +} + +count_pending=$(task status:pending count) +count_due=$(task due.before=tomorrow and due.after=today and -status:completed count) +count_overdue=$(task due.before=today and -status:completed count) +count_active=$(task +ACTIVE count) + +parts=("$(colorized "#8FAAFC" "${count_pending} pending")") + +if [ $count_due -gt 0 ]; then + parts+=("$(colorized "#FFD966" "${count_due} due")") +fi + +if [ $count_overdue -gt 0 ]; then + parts+=("$(colorized "#dd0000" "${count_overdue} overdue")") +fi + +if [ $count_active -gt 0 ]; then + active_tasks=$(task +ACTIVE export | jq -r '[ .[] | ["["+(.id|tostring)+"]", .description] | join(" ") ] | join(", ")') + parts+=("$(colorized "#50fa7b" "Active: ${active_tasks}")") +fi + +echo "$(printf '\uf0ae') $(join_by ", " "${parts[@]}")" diff --git a/bin/script_framework.sh b/bin/script_framework.sh index 2c02d01..49f098c 100644 --- a/bin/script_framework.sh +++ b/bin/script_framework.sh @@ -39,6 +39,14 @@ function info() { echo -e "${COLOR_CYAN}$@${COLOR_PLAIN}" >&2 } +function join_by() { + local d=$1 + shift + echo -n "$1" + shift + printf "%s" "${@/#/$d}" +} + function log_level_matches() { declare -A log_levels=( [debug]=0