From d9466664eb5e2e9ab0497c40e4cd8c0f26b1cff8 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 2 May 2023 11:00:08 +0800 Subject: Update --- bin/mail/log.sh | 34 ++++++++++++++++++++++++++++++++++ bin/mail/save_context.sh | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 bin/mail/log.sh create mode 100755 bin/mail/save_context.sh (limited to 'bin/mail') diff --git a/bin/mail/log.sh b/bin/mail/log.sh new file mode 100755 index 0000000..e96c9b4 --- /dev/null +++ b/bin/mail/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/mail/save_context.sh b/bin/mail/save_context.sh new file mode 100755 index 0000000..5cc9400 --- /dev/null +++ b/bin/mail/save_context.sh @@ -0,0 +1,19 @@ +#! /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: .*context@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 +cat <<<"$MAIL" >>~/Downloads/context.log + +# Save content to log file of current week +/home/pham/helper/bin/task/context $(awk -v RS= 'NR>1' <<<"$MAIL") + +/home/pham/helper/bin/task/context | cut -f1-3 | /usr/bin/mail -r context@topo.tw -C "chat-version: 1.0" -s no-reply pham + +cd ~/log && git add context/* && git commit -m 'Append time by mail' -- cgit v1.2.3-70-g09d2