Add remaining habits command

This commit is contained in:
Alex Selimov 2026-07-09 23:18:23 -04:00
parent f56778a8ae
commit b5b58c8b90

View file

@ -10,6 +10,7 @@ Usage: habits <command>
Commands: Commands:
open Open the habits file in $EDITOR open Open the habits file in $EDITOR
new Add a new day to the habits file new Add a new day to the habits file
left Print today's habits that are not done yet
EOF EOF
} }
@ -55,6 +56,24 @@ new_day() {
echo "Added $date to $HABITS_FILE" echo "Added $date to $HABITS_FILE"
} }
remaining_habits() {
ensure_file
local date
date="$(date +%F)"
awk -v date="$date" '
$0 == "# " date { in_day = 1; next }
in_day && /^# / { exit }
in_day && /^## Habits[[:space:]]*$/ { in_habits = 1; next }
in_day && in_habits && /^## / { exit }
in_day && in_habits && /^- \[ \] / {
sub(/^- \[ \] /, "")
print
}
' "$HABITS_FILE"
}
case "${1:-}" in case "${1:-}" in
open) open)
open_habits open_habits
@ -62,6 +81,9 @@ case "${1:-}" in
new) new)
new_day new_day
;; ;;
left)
remaining_habits
;;
-h|--help|help) -h|--help|help)
usage usage
;; ;;