forked from mk12/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoodnight.sh
More file actions
executable file
·81 lines (72 loc) · 1.9 KB
/
goodnight.sh
File metadata and controls
executable file
·81 lines (72 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
# This script moves the contents of Today.md to the end of $YYYY.md,
# preceded by a heading of the form "# Weekday, Day Month Year".
name=$(basename "$0")
usage="usage: $name [-hfdl] [-t file] [-j file] [-v[+|-]val[ymwdHMS]]"
today=~/Notes/Today.md
journal=$PROJECTS/journal/$(date +%Y).md
force=false
offset=-5H
language=false
while getopts ':t:j:v:hfdl' opt; do
case $opt in
f) force=true;;
t) today=$OPTAG;;
j) journal=$OPTARG;;
v) offset=$OPTARG;;
d) offset='-1d';;
l) language=true;;
h)
echo "$usage"
exit 0
;;
:)
echo "$name: $OPTARG: missing argument" >&2
echo "$usage" >&2
exit 1
;;
\?)
echo "$name: $OPTARG: illegal option" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [[ $force == true ]]; then
[[ -f $journal ]] || touch "$journal"
[[ -f $today ]] || touch "$today"
else
[[ -f $journal ]] || (echo "$name: $journal: no such file" >&2; exit 1)
[[ -f $today ]] || (echo "$name: $today: no such file" >&2; exit 1)
[[ -s $today ]] || (echo "$name: $today: file is empty" >&2; exit 1)
fi
year=$(date -v "$offset" +%Y)
month=$(date -v "$offset" +%B)
weekday=$(date -v "$offset" +%A)
day=$(date -v "$offset" +%e | xargs)
entry=$'\n'
entry+="# $weekday, $day $month $year"$'\n\n'
entry+=$(< "$today")
entry+=$'\n'
echo -n "$entry" >> "$journal"
if $language; then
if [[ "02468" == *"${day: -1}"* ]]; then
echo -n "English" > "$today"
else
echo -n "Français" > "$today"
fi
else
true > "$today"
fi
journallint "$journal"
cd "$(dirname "$journal")"
git add .
git diff --cached
read -rp "Commit? [Y/n]"
case $REPLY in
n|N) git reset; exit 0 ;;
esac
git commit -m "Add entry"
git push