Add remaining habits command
This commit is contained in:
parent
f56778a8ae
commit
b5b58c8b90
1 changed files with 24 additions and 2 deletions
22
habits.sh
22
habits.sh
|
|
@ -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
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue