diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-05-02 10:11:10 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-05-02 10:11:24 +0800 |
commit | 29b5d9481779a05cde5fe71fdddcf25c3b2e911a (patch) | |
tree | 5104237119f62bcde1c8407fd51a1b176facb621 /bin/wiki | |
parent | 19a01bf9d8a6396c6db0aa80c5a1925961e5002a (diff) |
Update
Diffstat (limited to 'bin/wiki')
-rwxr-xr-x | bin/wiki/diary | 49 | ||||
-rwxr-xr-x | bin/wiki/log.sh | 34 | ||||
-rwxr-xr-x | bin/wiki/notify | 7 |
3 files changed, 0 insertions, 90 deletions
diff --git a/bin/wiki/diary b/bin/wiki/diary deleted file mode 100755 index d9cbe83..0000000 --- a/bin/wiki/diary +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | today=~/log/`date +%y.w%W.md` | ||
4 | |||
5 | specify_date() { | ||
6 | YEAR=${YEAR:-23} | ||
7 | |||
8 | while read -e -p 'Month? ' -r MONTH </dev/tty; do | ||
9 | [ -z $MONTH ] && MONTH=$(date +%m) | ||
10 | MONTH=$(printf "%02d" $MONTH) | ||
11 | date -d $YEAR-$MONTH-01 &>/dev/null && break | ||
12 | done | ||
13 | |||
14 | while read -e -p 'Day? ' -r DAY </dev/tty; do | ||
15 | [ -z $DAY ] && DAY=$(date +%d) | ||
16 | DAY=$(printf "%02d" $DAY) | ||
17 | date -d $YEAR-$MONTH-$DAY &>/dev/null && break | ||
18 | done | ||
19 | |||
20 | FILE=~/log/diary/`date -d $YEAR-$MONTH-$DAY +%y.w%W.md` | ||
21 | $EDITOR -c 'Goyo' $FILE | ||
22 | } | ||
23 | |||
24 | print_today() { | ||
25 | [[ ! -e $today ]] && touch $today | ||
26 | cat $today | ||
27 | } | ||
28 | |||
29 | edit_today() { | ||
30 | $EDITOR -c Goyo $today | ||
31 | } | ||
32 | |||
33 | add_entry() { | ||
34 | [[ $# -ne 0 ]] && echo - "$@" >>$today | ||
35 | while read -e -r entry; do | ||
36 | echo $entry | sed -E 's/\t/ /g; s/(^[[:space:]]*)/\1- /' >>$today | ||
37 | done | ||
38 | } | ||
39 | |||
40 | case "$1" in | ||
41 | specify) | ||
42 | specify_date ;; | ||
43 | print) | ||
44 | print_today ;; | ||
45 | today) | ||
46 | edit_today ;; | ||
47 | *) | ||
48 | add_entry "$@" ;; | ||
49 | esac | ||
diff --git a/bin/wiki/log.sh b/bin/wiki/log.sh deleted file mode 100755 index e96c9b4..0000000 --- a/bin/wiki/log.sh +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
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/wiki/notify b/bin/wiki/notify deleted file mode 100755 index 6e510d8..0000000 --- a/bin/wiki/notify +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | exec >/dev/pts/$(ls /dev/pts -t | head -1) | ||
4 | |||
5 | echo | ||
6 | echo | ||
7 | cat | ||