summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/moonphase
blob: e90dc777ff990a84fab08f61307fc62412843733 (plain) (blame)
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
#!/bin/sh

# Shows the current moon phase.

moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"

[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
	{ curl -sf 'https://www.timeanddate.com/moon/phases/' | grep -m1 -o cur-moon-percent.......................................................................................................................................................... > "$moonfile" || exit 1 ;}

mnphs=$( cat $moonfile | grep -o 'New\|Waxing Crescent\|First Quarter\|Waxing Gibbous\|Full\|Waning Gibbous\|Last Quarter\|Waning Crescent' | grep -m1 '.')
prcnt=$( cat $moonfile | grep -o "[0-9.0-9]*%" | grep -o "[0-9.0-9]*" )
case "$mnphs" in
	"New") icon="🌑" prcnt="0" ;;
	"Waxing Crescent") icon="🌒" ;;
	"First Quarter") icon="🌓" prcnt="50" ;;
	"Waxing Gibbous") icon="🌔" ;;
	"Full") icon="🌕" prcnt="100" ;;
	"Waning Gibbous") icon="🌖" ;;
	"Last Quarter") icon="🌗" prcnt="50" ;;
	"Waning Crescent") icon="🌘" ;;
	*) echo exit 1 ;;
esac

echo ""$icon" "$prcnt"%"

case $BLOCK_BUTTON in
	3) notify-send "🌜 Moon phase module" "$icon: $mnphs $prcnt" ;;
	6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac