2022-10-08 12:47:57 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# network module for status/stellar
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# load config
|
2022-10-27 17:41:42 +02:00
|
|
|
. $HOME/.config/speedwm-de/statusrc
|
2022-10-25 19:23:36 +02:00
|
|
|
BINDIR="$(dirname $(command -v speedwm_status))/"
|
2022-10-21 13:35:02 +02:00
|
|
|
|
|
|
|
ARG1="$1"
|
|
|
|
|
|
|
|
|
|
|
|
# click
|
|
|
|
CLICK() {
|
|
|
|
# values
|
|
|
|
NETWORK_TRANSMITTED="$(awk '{$ARG1=$ARG1/1024000; print $ARG1"B";}' /sys/class/net/[ew]*/statistics/tx_bytes | sed "s/.*\(....\)/\1/; s|B|B/s |; s/[.]/0./")"
|
|
|
|
NETWORK_RECEIVED="$(awk '{$ARG1=$ARG1/1024000; print $ARG1"B";}' /sys/class/net/[ew]*/statistics/rx_bytes | sed "s/.*\(....\)/\1/; s|B|B/s |; s/[.]/0./")"
|
|
|
|
ICON="$ITEM6_ICON"
|
|
|
|
BUTTON="$(cat /tmp/speedwm-button)"
|
|
|
|
|
|
|
|
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
|
2022-10-08 18:07:28 +02:00
|
|
|
fi
|
2022-10-21 13:35:02 +02:00
|
|
|
|
|
|
|
# send the notification
|
|
|
|
SEND_NOTIF() {
|
|
|
|
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
|
2022-10-08 12:47:57 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# information itself
|
|
|
|
PRINT() {
|
|
|
|
if [ "$ENABLE_ITEM6" = "true" ]; then
|
|
|
|
if [ -e "${BINDIR}awk" ]; then
|
|
|
|
echo "$SEPARATOR $ITEM6_ICON $(awk '{$1=$1/1024000; print $1"B";}' /sys/class/net/[ew]*/statistics/tx_bytes | sed "s/.*\(....\)/\1/; s|B|B/s |; s/[.]/0./")"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# argument 1
|
|
|
|
case "$ARG1" in
|
|
|
|
"") CLICK ;;
|
|
|
|
"--print") PRINT > /tmp/module_net ;;
|
|
|
|
"--click") CLICK ;;
|
|
|
|
esac
|