-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy paththirsty.sh
More file actions
executable file
·39 lines (32 loc) · 874 Bytes
/
thirsty.sh
File metadata and controls
executable file
·39 lines (32 loc) · 874 Bytes
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
#!/bin/sh
WATER_TIME=${WATER_TIME:-1200} # Set time interval in seconds
DRINK_WATER_CONF="${DRINK_WATER_CONF:-$HOME/.water}"
drink_water() {
# If the file doesn't exist, create it
if [ ! -f $DRINK_WATER_CONF ]; then
date +%s > $DRINK_WATER_CONF
fi
# Tail is used to remain compatible with the pervious file format
next_time=$(($(tail -1 $DRINK_WATER_CONF) + $WATER_TIME))
if [ $next_time -lt $(date +%s) ]; then
echo -n "💧 You're thirsty"
fi
}
not_thirsty() {
date +%s > $DRINK_WATER_CONF
echo "Water is essential"
}
next_drink() {
next_time=$(($(cat $DRINK_WATER_CONF) + $WATER_TIME))
next_date=""
# Mac's date command uses a different flag
case "$(uname)" in
'Darwin')
next_date="$(date -r $next_time)"
;;
*)
next_date="$(date --date="@$next_time")"
;;
esac
echo "Next drink at $next_date"
}