swaydots

my dotfiles
git clone https://git.awy.one/swaydots.git
Log | Files | Refs | README | LICENSE

sb-nettraf (784B)


      1 #!/bin/sh
      2 
      3 # Module showing network traffic. Shows how much data has been received (RX) or
      4 # transmitted (TX) since the previous time this script ran. So if run every
      5 # second, gives network traffic per second.
      6 
      7 case $BLOCK_BUTTON in
      8   3) notify-send "🌐 Network traffic module" "🔻: Traffic received
      9 🔺: Traffic transmitted" ;;
     10   8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
     11 esac
     12 
     13 update() {
     14   sum=0
     15   for arg; do
     16     read -r i < "$arg"
     17     sum=$(( sum + i ))
     18   done
     19   cache=/tmp/${1##*/}
     20   [ -f "$cache" ] && read -r old < "$cache" || old=0
     21   printf %d\\n "$sum" > "$cache"
     22   printf %d\\n $(( sum - old ))
     23 }
     24 
     25 rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
     26 tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
     27 
     28 printf "🔻%4sB 🔺%4sB\\n" $(numfmt --to=iec $rx $tx)