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/init/load-settings.sh | 2 ++ bin/log/log.sh | 34 ---------------------------------- bin/mail/log.sh | 34 ++++++++++++++++++++++++++++++++++ bin/mail/save_context.sh | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+), 34 deletions(-) delete mode 100755 bin/log/log.sh create mode 100755 bin/mail/log.sh create mode 100755 bin/mail/save_context.sh diff --git a/bin/init/load-settings.sh b/bin/init/load-settings.sh index 960f407..d3e092b 100755 --- a/bin/init/load-settings.sh +++ b/bin/init/load-settings.sh @@ -17,6 +17,8 @@ export shell=${shell##*/} # load custom aliases source $SETTING_DIR/alias + +# sourcr rc files [[ -d $SETTING_DIR/private ]] && for f in $SETTING_DIR/private/*; do source $f; done find $SETTING_DIR/bin -not -executable -name '*rc' | while read rcfile; do source $rcfile; done diff --git a/bin/log/log.sh b/bin/log/log.sh deleted file mode 100755 index e96c9b4..0000000 --- a/bin/log/log.sh +++ /dev/null @@ -1,34 +0,0 @@ -#! /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/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