today

what did you do today?
git clone git://git.alexkarle.com.com/today
Log | Files | Refs | README | LICENSE

commit a3f9efadf9915d29d5ef18b8966e1b60b633c7ec (patch)
parent 36af8fe113cd82921eefe3c5509073b046ea6fbd
Author: Alex Karle <alex@alexkarle.com>
Date:   Thu,  3 Mar 2022 23:07:08 -0500

Remove -n/-e new/edit choice from usage (auto-choose)

Now, when run without arguments, the command either edits
the existing entry or starts a new one.

Diffstat:
MREADME | 12+++++-------
Mtoday | 22++++++++++++++--------
Mtoday.1 | 13++++++-------
3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/README b/README @@ -4,7 +4,7 @@ NAME today - what did you do today? SYNOPSIS - today [-ein] [-l [NUM]] + today [-hi] [-l [NUM]] DESCRIPTION today is a tool for quickly documenting a day's work at the end of @@ -19,13 +19,10 @@ DESCRIPTION The options are as follows: - -e edit the most recent day's notes. + -h display the help message and exit -i initialize the today repository. - -n start a new day's entry, indicated by a [YYYY-MM-DD] - separator. - -l [NUM] list the last NUM days-worth of entries, or all if NUM not given. @@ -36,7 +33,8 @@ ENVIRONMENT FILES $TODAY_DIR Git repository - $TODAY_DIR/log Log file + $TODAY_DIR/log Log file. Entries are separated by [YYYY-MM-DD] + entries. EXAMPLES One time setup: @@ -45,7 +43,7 @@ EXAMPLES Jot down what you did today: - $ today -n + $ today ed> a * Learned some mdoc(7) * Rewrote today(1) diff --git a/today b/today @@ -48,8 +48,14 @@ edlog() { commit "Auto commit" } -new() { - printf "\n[%s]\n" "$(date "+%F")" >> "$LOG" +edit() { + now=$(printf "[%s]" "$(date "+%F")") + if grep -q "^\[$(date "+%F")\]\$" "$LOG"; then + echo "Entry for today already exists, editing" + else + echo "Starting a new entry for today $now" + printf "\n$now\n" >> "$LOG" + fi edlog } @@ -76,13 +82,13 @@ list() { esac } -case "$1" in - -e) reqinit && edlog ;; - -i) init ;; - -n) reqinit && new ;; - -l) reqinit && list "$2" ;; +case "x$1" in + x) edit ;; + x-i) init ;; + x-l) reqinit && list "$2" ;; + x-h) die "usage: today [-hi] [-l [NUM]]" ;; *) [ -n "$1" ] && err "error: unknown option $1" - die "usage: today [-ein] [-l [NUM]]" + die "usage: today [-i]h [-l [NUM]]" ;; esac diff --git a/today.1 b/today.1 @@ -6,7 +6,7 @@ .Nd what did you do today? .Sh SYNOPSIS .Nm -.Op Fl ein +.Op Fl hi .Op Fl l Op Ar NUM .Sh DESCRIPTION .Nm @@ -33,14 +33,12 @@ append-only mindset for recording whatever is top of mind. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl e -edit the most recent day's notes. +.It Fl h +display the help message and exit .It Fl i initialize the .Nm repository. -.It Fl n -start a new day's entry, indicated by a [YYYY-MM-DD] separator. .It Fl l Op Ar NUM list the last .Ar NUM @@ -60,7 +58,8 @@ override the default repo location, .It Pa $TODAY_DIR Git repository .It Pa $TODAY_DIR/log -Log file +Log file. +Entries are separated by [YYYY-MM-DD] entries. .El .Sh EXAMPLES One time setup: @@ -69,7 +68,7 @@ One time setup: .Pp Jot down what you did today: .Bd -literal -offset indent -$ today -n +$ today ed> a * Learned some mdoc(7) * Rewrote today(1)