Add remaining habits command
This commit is contained in:
parent
f56778a8ae
commit
b5b58c8b90
1 changed files with 24 additions and 2 deletions
26
habits.sh
26
habits.sh
|
|
@ -8,8 +8,9 @@ usage() {
|
|||
Usage: habits <command>
|
||||
|
||||
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
|
||||
;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue