diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-05-02 11:00:08 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-05-02 11:00:08 +0800 |
| commit | d9466664eb5e2e9ab0497c40e4cd8c0f26b1cff8 (patch) | |
| tree | ace4c910dd888f641286e7302f52119afb2d004e /bin/mail | |
| parent | 29b5d9481779a05cde5fe71fdddcf25c3b2e911a (diff) | |
Update
Diffstat (limited to 'bin/mail')
| -rwxr-xr-x | bin/mail/log.sh | 34 | ||||
| -rwxr-xr-x | bin/mail/save_context.sh | 19 |
2 files changed, 53 insertions, 0 deletions
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 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | # Restore mail in variable | ||
| 4 | MAIL="$(cat)" | ||
| 5 | |||
| 6 | # Only execute the following script when mail receiver is log@topo.tw | ||
| 7 | grep -qE "^X-Original-To: .*log@topo.tw[>]?$" <<<"$MAIL" || exit 0 | ||
| 8 | # A little hacky way to check if mail is sent from me | ||
| 9 | sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 | ||
| 10 | |||
| 11 | # Write a log | ||
| 12 | date >>~/Downloads/log.log | ||
| 13 | echo $$ >>~/Downloads/log.log | ||
| 14 | awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/log.log | ||
| 15 | |||
| 16 | LOG=~/log/`date +%y.w%W.md` | ||
| 17 | TODAY="`date '+%a %b.%d'`" | ||
| 18 | |||
| 19 | # If header of today doesn't exist | ||
| 20 | # Create it and separate with 2 empty lines | ||
| 21 | grep -Eq "^## ${TODAY}$" ${LOG} || \ | ||
| 22 | cat <<EOF >>${LOG} | ||
| 23 | |||
| 24 | |||
| 25 | ## $TODAY | ||
| 26 | EOF | ||
| 27 | |||
| 28 | |||
| 29 | # Save content to log file of current week | ||
| 30 | echo >>${LOG} | ||
| 31 | awk -v RS= 'NR>1' <<<"$MAIL" >>${LOG} | ||
| 32 | |||
| 33 | # git commit | ||
| 34 | { 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 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | # Restore mail in variable | ||
| 4 | MAIL="$(cat)" | ||
| 5 | |||
| 6 | # Only execute the following script when mail receiver is log@topo.tw | ||
| 7 | grep -qE "^X-Original-To: .*context@topo.tw[>]?$" <<<"$MAIL" || exit 0 | ||
| 8 | # A little hacky way to check if mail is sent from me | ||
| 9 | sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 | ||
| 10 | |||
| 11 | # Write a log | ||
| 12 | cat <<<"$MAIL" >>~/Downloads/context.log | ||
| 13 | |||
| 14 | # Save content to log file of current week | ||
| 15 | /home/pham/helper/bin/task/context $(awk -v RS= 'NR>1' <<<"$MAIL") | ||
| 16 | |||
| 17 | /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 | ||
| 18 | |||
| 19 | cd ~/log && git add context/* && git commit -m 'Append time by mail' | ||