summaryrefslogtreecommitdiff
path: root/journal.sh
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-08-28 14:25:12 -0400
committerShav Kinderlehrer <[email protected]>2023-08-28 14:25:12 -0400
commit03c6e4705c3eb13bdcc6ca1b55b11ca5fd088a94 (patch)
tree96f48b21689cada18b69aad87d70b7ccbfb96e87 /journal.sh
parent93fadc393e82c032b829ae20e301ee0bc3f77851 (diff)
downloadscripts-03c6e4705c3eb13bdcc6ca1b55b11ca5fd088a94.tar.gz
scripts-03c6e4705c3eb13bdcc6ca1b55b11ca5fd088a94.zip
Add journal.sh
Manages simply blog entries
Diffstat (limited to 'journal.sh')
-rwxr-xr-xjournal.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/journal.sh b/journal.sh
new file mode 100755
index 0000000..903440f
--- /dev/null
+++ b/journal.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env zsh
+
+set_dates() {
+ nowtime=$(gdate "+%H:%M") || exit
+ day=$(gdate "+%A" -d "$*") || exit
+ daynum=$(gdate "+%e" -d "$*") || exit
+ month=$(gdate "+%m" -d "$*") || exit
+ year=$(gdate "+%Y" -d "$*") || exit
+ date=$(gdate "+%Y-%m-%d" -d "$*") || exit
+
+ date_path=$(gdate "+%Y/%m" -d "$*") || exit
+ journal_prefix=~/code/txt/cal
+ file="$journal_prefix/$date_path/$date.txt"
+}
+
+change_status="Edited"
+
+for arg in $@
+case "$arg" in
+ show)
+ shift
+ set_dates $*
+ if [ ! -f "$file" ]; then
+ printf "journal entry for $date not found.\n"
+ exit 1;
+ fi
+
+ if [[ $(wc -l < $file) -le $["$LINES" - 20] ]]; then
+ cat "$file"
+ else
+ $PAGER "$file"
+ fi
+
+
+ exit 0
+esac
+
+set_dates $*
+cd "$journal_prefix"
+
+#setup header
+if [ ! -f "$file" ]; then
+ mkdir -p $(dirname "$file") 2> /dev/null
+
+ printf "%0.s=" {1..13} >> $file
+ printf "\n" >> $file
+ cal -h "$month" "$year" | gsed "0,/$daynum/{s//XX/}" >> $file
+ truncate -s -1 $file
+
+ printf "\n$day\n" >> $file
+ printf "%0.s=" {1..13} >> $file
+ printf "\n" >> $file
+
+ change_status="Created"
+fi
+
+if ! grep -xq "$nowtime" "$file"; then
+ printf "\n* At $nowtime\n" >> $file
+fi
+
+$EDITOR $file
+
+stty sane
+printf "Save in git? [Y|n]: "
+read yn
+case $yn in
+ Y|y| )
+ git add "$file"
+ git commit -S -m "$change_status entry for $date at $nowtime" -m "$(randomart.py --ascii "$file")"
+esac