1
0
Fork 0
dotfiles/.local/libexec/statusbar/sb-nettraf

18 lines
507 B
Bash
Executable file

#!/bin/sh
. "$HOME/.local/libexec/statusbar/colors"
update() {
sum=0
for arg; do
read -r i <"$arg"
sum=$((sum + i))
done
cache=/tmp/${1##*/}
[ -f "$cache" ] && read -r old <"$cache" || old=0
printf "%b" "$sum\n" >"$cache"
printf "%b" "$((sum - old))\n"
}
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
printf "%b%5sB %b%5sB%b" "<span$big></span>" "$(numfmt --to=iec "$rx")" "<span $big></span>" "$(numfmt --to=iec "$tx")" "\n"