speedwm-personal/modules/module_weather

57 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# weather module for status/stellar
# load config
module_config
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
[ "$ENABLE_ITEM5" = "true" ] || exit
command -v curl > /dev/null || exit
WEATHER_FULL="$(echo "$(curl -s wttr.in/?format="%C" || exit), $(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/')")"
2022-11-28 20:32:25 +01:00
echo "$WEATHER_FULL" | grep -qE "Unknown location|<html>| ," && exit
# clicking
CLICK() {
# values
WEATHER_TERM="speedwm-core -curl-weather"
ICON="$ITEM5_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
[ -z "$TERMINAL" ] && TERMINAL=st
[ ! -z "$ICON" ] && ICONSPACING=" " # one character spacing
# check value of button
case "$BUTTON" in
"3") $TERMINAL "clear ; curl -s wttr.in | head -n 38 | tail -n 37 ; read a ; return " ;;
esac
# send the notification
SEND_NOTIF() {
FULL_WEATHER="${ICON}${ICONSPACING}$WEATHER_FULL"
notify-send "$FULL_WEATHER"
# some information
echo "Notification sent successfully!"
echo "INFO: $FULL_WEATHER"
return
}
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
return
}
# information itself
PRINT() {
echo "$ITEM5_SEPARATOR $ITEM5_ICON $WEATHER_FULL"
}
# argument 1
case "$1" in
"") CLICK ;;
"--print-file") PRINT > /tmp/module_weather ;;
"--print") PRINT ;;
"--click") CLICK ;;
esac