-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiary.sh
executable file
·82 lines (67 loc) · 1.24 KB
/
diary.sh
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
82
#!/bin/bash
# usage: diary "DIARY ENTRY" [DIARY FILE] [-u]
# place a .tinydiary in your home directory with your desired default
# diary file
#
eval DIARY_CONFIG="~/.tinydiary"
diary_file=
text=
append=0
if [[ "$1" = "help" ]]
then
echo "usage: diary "ENTRY" [FILE] [-u] [help]"
exit 0
fi
while :;
do
if [ -z "$1" ]; then break; fi
if [[ "$1" = "-u" ]]
then
echo "undo"
exit 0
fi
if [[ "$1" = "-a" ]]
then
append=1
elif [ -z "$text" ]
then
text=$1
else
eval filename="$1"
diary_file="$filename"
fi
shift
done
if [ -z $diary_file ]
then
if [ -e "$DIARY_CONFIG" ]
then
while IFS= read -r line
do
eval diary_file=$line
done < "$DIARY_CONFIG"
if [ -z $diary_file ]
then
echo "please specify a default diary file in .tinydiary"
exit 1
fi
else
echo "no ~/.tinydiary"
exit 2
fi
fi
if [ -z "$text" ]
then
if [ -e "$diary_file" ]
then
cat $diary_file | less
fi
exit 0
fi
if [ $append -eq 0 ]; then
output="$(date)\n$text\n\n"
else
output="$text\n\n"
fi
printf "$output" | tee -a "$diary_file"
printf ">> $diary_file\n"