-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoonphase
94 lines (91 loc) · 1.7 KB
/
moonphase
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
#!/bin/sh
# moonphase
originmoon=$(date +%s -d "2021-04-12 02:30 GMT")
now=$(date +%s)
lunarday=29.5305877076
modulo=$(genius --exec="$lunarday * (24 * 60 * 60)")
seconds=$(genius --exec="$now - $originmoon")
current=$(genius --exec="$seconds mod IntegerPart($modulo)")
fraction=$(genius --exec="$current / $modulo")
phase=$(genius --exec="round($fraction * $lunarday)")
lunation=$(genius --exec="round(100 * $fraction)")
case $phase in
1|29)
icon="\uF095";;
2)
icon="\uF096";;
3)
icon="\uF097";;
4)
icon="\uF098";;
5)
icon="\uF099";;
6)
icon="\uF09A";;
7)
icon="\uF09B";;
8)
icon="\uF09C";;
9)
icon="\uF09D";;
10)
icon="\uF09E";;
11)
icon="\uF09F";;
12)
icon="\uF0A0";;
13)
icon="\uF0A1";;
14)
icon="\uF0A2";;
15)
icon="\uF0A3";;
16)
icon="\uF0A4";;
17)
icon="\uF0A5";;
18)
icon="\uF0A6";;
19)
icon="\uF0A7";;
20)
icon="\uF0A8";;
21)
icon="\uF0A9";;
22)
icon="\uF0AA";;
23)
icon="\uF0AB";;
24)
icon="\uF0AC";;
25)
icon="\uF0AD";;
26)
icon="\uF0AE";;
27)
icon="\uF0A9";;
28)
icon="\uF0B0";;
esac
if [ $lunation -le 2 ]; then phase_text="New Moon"
elif [ $lunation -lt 25 ]; then phase_text="Waxing Crescent"
elif [ $lunation -le 26 ]; then phase_text="First Quarter"
elif [ $lunation -lt 49 ]; then phase_text="Waxing Gibbous"
elif [ $lunation -le 51 ]; then phase_text="Full Moon"
elif [ $lunation -lt 75 ]; then phase_text="Waning Gibbous"
elif [ $lunation -le 76 ]; then phase_text="Last Quarter"
elif [ $lunation -lt 100 ]; then phase_text="Waning Crescent"
elif [ $lunation -eq 100 ]; then phase_text="New Moon"
else
phase_text="New Moon" # new
fi
case $1 in
-i|-icon)
echo -e $icon;;
-t|-text)
echo $phase_text;;
-l|-lunation)
echo "$lunation%";;
*)
echo -e "$phase_text $icon $phase $lunation%";;
esac