summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/moonphase
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/statusbar/moonphase')
-rwxr-xr-x.local/bin/statusbar/moonphase46
1 files changed, 29 insertions, 17 deletions
diff --git a/.local/bin/statusbar/moonphase b/.local/bin/statusbar/moonphase
index 2d9f91f..fab8b4d 100755
--- a/.local/bin/statusbar/moonphase
+++ b/.local/bin/statusbar/moonphase
@@ -1,25 +1,37 @@
#!/bin/sh
-# Shows the current moon phase. Requires `pom-perl`.
+# Shows the current moon phase.
-mnphs=$(pom $1 | grep -o 'New\|Waxing Crescent\|First Quarter\|Waxing Gibbous\|Full\|Waning Gibbous\|Last Quarter\|Waning Crescent' | grep -m1 '.') || exit 1
-prcnt=$(pom $1 | grep -o '[[:digit:]]*%' | grep -o '[[:digit:]]*' )
-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="🌘" ;;
+moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"
+
+[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
+ { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;}
+
+icon="$(cat "$moonfile")"
+
+case "$icon" in
+ 🌑) name="New" ;;
+ 🌒) name="Waxing Crescent" ;;
+ 🌓) name="First Quarter" ;;
+ 🌔) name="Waxing Gibbous" ;;
+ 🌕) name="Full" ;;
+ 🌖) name="Waning Gibbous" ;;
+ 🌗) name="Last Quarter" ;;
+ 🌘) name="Waning Crescent" ;;
+ *) exit 1 ;;
esac
+echo "${icon-?}"
+
case $BLOCK_BUTTON in
- 1) $mnphs ;;
- 2) $mnphs ;;
- 3) notify-send " 🌜$(pom)" ;;
+ 3) notify-send "🌜 Moon phase module" "Displays current moon phase.
+- 🌑: New
+- 🌒: Waxing Crescent
+- 🌓: First Quarter
+- 🌔: Waxing Gibbous
+- 🌕: Full
+- 🌖: Waning Gibbous
+- 🌗: Last Quarter
+- 🌘: Waning Crescent" ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
-
-echo "${icon:?}" "$prcnt"%