diff --git a/habits.sh b/habits.sh index 0b81fb7..3ae7be7 100755 --- a/habits.sh +++ b/habits.sh @@ -8,8 +8,9 @@ usage() { Usage: habits Commands: - open Open the habits file in $EDITOR - new Add a new day to the habits file + open Open the habits file in $EDITOR + new Add a new day to the habits file + left Print today's habits that are not done yet EOF } @@ -55,6 +56,24 @@ new_day() { 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 open) open_habits @@ -62,6 +81,9 @@ case "${1:-}" in new) new_day ;; + left) + remaining_habits + ;; -h|--help|help) usage ;;