speedwm-personal/modules/module_temp

79 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-10-08 14:36:30 +02:00
#!/bin/sh
# cpu temp module for status/stellar
# load config
2022-10-27 17:51:19 +02:00
. $HOME/.config/speedwm/statusrc
2022-10-25 19:23:36 +02:00
BINDIR="$(dirname $(command -v speedwm_status))/"
2022-10-08 14:36:30 +02:00
ARG1="$1"
# click
CLICK() {
# values
ICON="$ITEM8_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
if [ "$ITEM8_FORMAT_CELSIUS" != "true" ]; then
FARG="-F"
fi
if [ ! -e "/tmp/iscelsius" ]; then
if [ "$FARG" = "" ]; then
FARG="-F"
fi
fi
TEMP_FULL="$(sensors $FARG)"
command -v sensors > /dev/null || exit 1
case "$TERMINAL" in
"") TERMINAL=st
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_TEMP="${ICON}${ICONSPACING}$TEMP_FULL"
notify-send "$FULL_TEMP"
echo "Notification sent successfully!"
echo "INFO: $FULL_TEMP"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1
2022-10-08 14:36:30 +02:00
}
# information itself
PRINT() {
if [ "$ENABLE_ITEM8" = "true" ]; then
if [ -e "${BINDIR}sensors" ]; then
if [ "$ITEM8_FORMAT_CELSIUS" = "true" ]; then
2022-11-01 20:47:46 +01:00
sensors | grep temp1 | awk '{ print $2 }' | grep -q "C" && echo "$SEPARATOR $ITEM8_ICON $(sensors | grep temp1 | awk '{ print $2 }')"
touch /tmp/iscelsius
else
2022-11-01 20:47:46 +01:00
sensors | grep temp1 | awk '{ print $2 }' | grep -q "F" && echo "$SEPARATOR $ITEM8_ICON $(sensors -f | grep temp1 | awk '{ print $2 }')"
fi
fi
fi
}
2022-10-08 14:36:30 +02:00
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print") PRINT > /tmp/module_temp ;;
"--click") CLICK ;;
esac
2022-11-01 20:47:46 +01:00
if [ "$(cat /tmp/module_temp | wc -c)" -lt "6" ]; then
rm -f /tmp/module_temp
fi