-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbash-fuzzy-clock.sh
executable file
·216 lines (198 loc) · 5.19 KB
/
bash-fuzzy-clock.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env bash
# BASH fuzzyclock
# by Corey Mwamba
#
export TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAIN=bash-fuzzy-clock
hr=($(date '+%_H'))
min=10#$(date '+%M')
nearly=$"nearly"
oclock=($"o'clock")
if [[ "${LANGUAGE:0:2}" != "" ]] ; then
lng="${LANGUAGE:0:2}"
elif [[ "${LANG:0:2}" != "" ]] ; then
lng="${LANG:0:2}"
fi
# To my knowledge, there is no natural way to say
# "just after four", for example, in brazilian portuguese
case $lng in
pt)
justaft=""
;;
*)
justaft=$"just after"
;;
esac
if [[ $((min % 5)) -gt 0 ]];then
if [[ $((min % 5)) -lt 3 ]]; then
adv=$justaft
else
adv=$nearly
fi
fi
case "$1" in
meri|m)
if [[ $hr -gt 0 && $hr -lt 12 ]]; then
echo $"morning"
elif [[ $hr -ge 12 && $hr -lt 18 ]]; then
echo $"afternoon"
elif [[ $hr -ge 18 && $hr -lt 21 ]]; then
echo $"evening"
else
echo $"night"
fi
;;
*)
if [[ $min -gt 27 && $min -lt 33 ]]; then
adj=$"half past"
case "$lng" in
de)
hr=$((hr + 1))
if [[ $hr -eq 24 ]]; then
hr=0
fi
esac
fi
case "$lng" in
pt)
if [[ $min -ge 37 ]]; then
hr=$((hr + 1))
if [[ $hr -eq 24 ]]; then
hr=0
fi
fi
;;
*)
if [[ $min -ge 33 ]]; then
hr=$((hr + 1))
if [[ $hr -eq 24 ]]; then
hr=0
fi
fi
esac
case $hr in
1|13)
th=$"one"
;;
2|14)
th=$"two"
;;
3|15)
th=$"three"
;;
4|16)
th=$"four"
;;
5|17)
th=$"five"
;;
6|18)
th=$"six"
;;
7|19)
th=$"seven"
;;
8|20)
th=$"eight"
;;
9|21)
th=$"nine"
;;
10|22)
th=$"ten"
;;
11|23)
th=$"eleven"
;;
0)
th=$"midnight"
;;
12)
th=$"midday"
esac
# French and Spanish use an hour declaration all the time
# Italian does not
# Most other languages treat one as a singular hour
#
# But this might change if other languages are added.
# I need to be able to control this better...
case "$lng" in
fr|es)
if [[ $hr -eq 1 || $hr -eq 13 ]]; then
manner=$"hour"
else
manner=$oclock
fi
;;
*)
if [[ $hr -ne 12 && $hr -ne 0 ]]; then
if [[ $min -gt 57 || $min -lt 3 ]]; then
manner=$oclock
fi
fi
esac
if [[ $min -ge 3 && $min -le 7 ]]; then
adj=$"five past"
fi
if [[ $min -gt 7 && $min -lt 13 ]]; then
adj=$"ten past"
fi
if [[ $min -ge 13 && $min -le 17 ]]; then
adj=$"quarter past"
fi
if [[ $min -gt 17 && $min -lt 23 ]]; then
adj=$"twenty past"
fi
if [[ $min -ge 23 && $min -le 27 ]]; then
adj=$"twenty-five past"
fi
if [[ $min -ge 33 && $min -le 37 ]]; then
adj=$"twenty-five to"
fi
if [[ $min -gt 37 && $min -lt 43 ]]; then
adj=$"twenty to"
fi
if [[ $min -ge 43 && $min -le 47 ]]; then
adj=$"quarter to"
fi
if [[ $min -gt 47 && $min -lt 53 ]]; then
adj=$"ten to"
fi
if [[ $min -ge 53 && $min -le 57 ]]; then
adj=$"five to"
fi
if [[ -z "$adv" && -z "$adj" ]]; then
printf $"$th $manner\n"
fi
if [[ -z "$adv" && -n "$adj" ]]; then
case $lng in
pt)
if [[ $min -lt 37 ]]; then
printf $"$adj $th $manner\n"
else
printf $"$adj $th\n"
fi
;;
*)
printf $"$adj $th $manner\n"
;;
esac
fi
if [[ -n "$adv" && -z "$adj" ]]; then
printf $"$adv $th $manner\n"
fi
if [[ -n "$adv" && -n "$adj" ]]; then
case $lng in
pt)
if [[ $min -lt 37 ]]; then
printf $"$adv $adj $th $manner\n"
else
printf $"$adv $adj $th\n"
fi
;;
*)
printf $"$adv $adj $th $manner\n"
;;
esac
fi
esac