summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2022-11-02 10:19:28 +0800
committerGuangxiong Lin <[email protected]>2022-11-02 10:19:28 +0800
commite3cc18281fff870eefa9413313470638081d9ae1 (patch)
tree0e2ab8782f57a41aa82e67b3c3fe05f0ef4b7213
parent7353932f6d6fbf0b791a159d29c1933902a7d00d (diff)
downloadwd-0.0.5.tar.gz
wd-0.0.5.tar.bz2
wd-0.0.5.zip
Support monthly journalv0.0.5
-rwxr-xr-xwd-journal49
1 files changed, 42 insertions, 7 deletions
diff --git a/wd-journal b/wd-journal
index 7f59649..4fa6f84 100755
--- a/wd-journal
+++ b/wd-journal
@@ -3,15 +3,50 @@
year=$(date +%Y)
week_number=$(date +%W)
-overall_title="# Week $week_number $year"
-today_title="## $(date '+%Y-%m-%d %A')"
+weekly_journal_title="# Week $week_number $year"
+weekly_journal_subtitle="## $(date '+%Y-%m-%d %A')"
+
+monthly_journal_title="# $(date '+%B %Y')"
+monthly_journal_subtitle="## [Week $week_number $year](week$week_number.md)"
weekly_journal="$WD_JOURNALS_DIR/$year/week$week_number.md"
+monthly_journal="$WD_JOURNALS_DIR/$year/$(date '+%Y-%m').md"
+
+# Open weekly journal by default.
+# TODO: maybe I can add a environment variable on it.
+file_to_edit="$weekly_journal"
+
+init_journal_with_title () {
+ local filepath=$1
+ local journal_title=$2
+
+ [ ! -f "$filepath" ] && echo "$journal_title" > "$filepath"
+}
+
+append_line_if_not_in_file () {
+ local filepath=$1
+ local line=$2
+
+ if ! grep -q "$line" "$filepath"; then
+ echo "$line" >> "$filepath"
+ fi
+}
+
+init_weekly_journal () {
+ init_journal_with_title "$weekly_journal" "$weekly_journal_title"
+
+ append_line_if_not_in_file "$weekly_journal" "$weekly_journal_subtitle"
+}
+
+init_monthly_journal () {
+ init_journal_with_title "$monthly_journal" "$monthly_journal_title"
-[ ! -f "$weekly_journal" ] && echo "$overall_title" > "$weekly_journal"
+ append_line_if_not_in_file "$monthly_journal" "$monthly_journal_subtitle"
+}
-if ! grep -q "$today_title" "$weekly_journal"; then
- echo "$today_title" >> "$weekly_journal"
-fi
+case "$1" in
+ --monthly|-m) shift; init_monthly_journal; file_to_edit="$monthly_journal";;
+ --weekly|-w) shift; init_weekly_journal; file_to_edit="$weekly_journal";;
+esac
-$EDITOR "$WD_JOURNALS_DIR/$year/week$week_number.md"
+$EDITOR "$file_to_edit"