From 29b5d9481779a05cde5fe71fdddcf25c3b2e911a Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 2 May 2023 10:11:10 +0800 Subject: Update --- bin/log/diary | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ bin/log/log.sh | 34 ++++++++++++++++++++++++++++++++++ bin/log/notify | 7 +++++++ 3 files changed, 90 insertions(+) create mode 100755 bin/log/diary create mode 100755 bin/log/log.sh create mode 100755 bin/log/notify (limited to 'bin/log') diff --git a/bin/log/diary b/bin/log/diary new file mode 100755 index 0000000..d9cbe83 --- /dev/null +++ b/bin/log/diary @@ -0,0 +1,49 @@ +#! /bin/bash + +today=~/log/`date +%y.w%W.md` + +specify_date() { + YEAR=${YEAR:-23} + + while read -e -p 'Month? ' -r MONTH /dev/null && break + done + + while read -e -p 'Day? ' -r DAY /dev/null && break + done + + FILE=~/log/diary/`date -d $YEAR-$MONTH-$DAY +%y.w%W.md` + $EDITOR -c 'Goyo' $FILE +} + +print_today() { + [[ ! -e $today ]] && touch $today + cat $today +} + +edit_today() { + $EDITOR -c Goyo $today +} + +add_entry() { + [[ $# -ne 0 ]] && echo - "$@" >>$today + while read -e -r entry; do + echo $entry | sed -E 's/\t/ /g; s/(^[[:space:]]*)/\1- /' >>$today + done +} + +case "$1" in + specify) + specify_date ;; + print) + print_today ;; + today) + edit_today ;; + *) + add_entry "$@" ;; +esac diff --git a/bin/log/log.sh b/bin/log/log.sh new file mode 100755 index 0000000..e96c9b4 --- /dev/null +++ b/bin/log/log.sh @@ -0,0 +1,34 @@ +#! /bin/bash + +# Restore mail in variable +MAIL="$(cat)" + +# Only execute the following script when mail receiver is log@topo.tw +grep -qE "^X-Original-To: .*log@topo.tw[>]?$" <<<"$MAIL" || exit 0 +# A little hacky way to check if mail is sent from me +sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 + +# Write a log +date >>~/Downloads/log.log +echo $$ >>~/Downloads/log.log +awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/log.log + +LOG=~/log/`date +%y.w%W.md` +TODAY="`date '+%a %b.%d'`" + +# If header of today doesn't exist +# Create it and separate with 2 empty lines +grep -Eq "^## ${TODAY}$" ${LOG} || \ +cat <>${LOG} + + +## $TODAY +EOF + + +# Save content to log file of current week +echo >>${LOG} +awk -v RS= 'NR>1' <<<"$MAIL" >>${LOG} + +# git commit +{ cd ~/log && git add `basename ${LOG}` && git commit -m "Update by mail"; } >>~/Downloads/log.log diff --git a/bin/log/notify b/bin/log/notify new file mode 100755 index 0000000..6e510d8 --- /dev/null +++ b/bin/log/notify @@ -0,0 +1,7 @@ +#! /bin/sh + +exec >/dev/pts/$(ls /dev/pts -t | head -1) + +echo +echo +cat -- cgit v1.2.3-70-g09d2