speedwm-personal/modules/module_net

46 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# network module for status/stellar
# values
NETWORK_TRANSMITTED="$(awk '{$1=$1/1024000; print $1"B";}' /sys/class/net/[ew]*/statistics/tx_bytes | sed "s/.*\(....\)/\1/; s|B|B/s |; s/[.]/0./")"
NETWORK_RECEIVED="$(awk '{$1=$1/1024000; print $1"B";}' /sys/class/net/[ew]*/statistics/rx_bytes | sed "s/.*\(....\)/\1/; s|B|B/s |; s/[.]/0./")"
ICON="$1"
BUTTON="$(cat /tmp/speedwm-button)"
# load status config
if [ -e "$HOME/.config/speedwm-de/status/config" ]; then
. $HOME/.config/speedwm-de/status/config
if [ "$1" = "" ]; then
ICON="$ITEM6_ICON"
fi
fi
case "$TERMINAL" in
"") TERMINAL=st
esac
case "$BUTTON" in
"3") $TERMINAL -e bmon ; exit ;;
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
2022-10-08 12:56:16 +02:00
FULL_NETWORK="${ICON}${ICONSPACING}${NETWORK_TRANSMITTED}transmitted, ${NETWORK_RECEIVED}received."
notify-send "$FULL_NETWORK"
echo "Notification sent successfully!"
echo "INFO: $FULL_NETWORK"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1