4 # - Moritz Warning <moritzwarning@web.de> (2016)
5 # - Zhong Jianxin <azuwis@gmail.com> (2014)
7 # See file LICENSE at the project root directory for license information.
9 # i3status.conf should contain:
11 # output_format = i3bar
14 # i3 config looks like this:
16 # status_command exec /usr/share/doc/i3status/contrib/net-speed.sh
22 # Multiple interfaces:
26 # Auto detect interfaces
27 ifaces=$(ls /sys/class/net | grep -E '^(eth|wlan|enp|wlp)')
36 local kib=$(( bytes >> 10 ))
37 if [ $kib -lt 0 ]; then
39 elif [ $kib -gt 1024 ]; then
40 local mib_int=$(( kib >> 10 ))
41 local mib_dec=$(( kib % 1024 * 976 / 10000 ))
42 if [ "$mib_dec" -lt 10 ]; then
45 echo "${mib_int}.${mib_dec} M"
52 local time=$(date +%s)
53 local rx=0 tx=0 tmp_rx tmp_tx
55 for iface in $ifaces; do
56 read tmp_rx < "/sys/class/net/${iface}/statistics/rx_bytes"
57 read tmp_tx < "/sys/class/net/${iface}/statistics/tx_bytes"
62 local interval=$(( $time - $last_time ))
63 if [ $interval -gt 0 ]; then
64 rate="$(readable $(( (rx - last_rx) / interval )))↓ $(readable $(( (tx - last_tx) / interval )))↑"
74 i3status | (read line && echo "$line" && read line && echo "$line" && read line && echo "$line" && update_rate && while :
78 echo ",[{\"full_text\":\"${rate}\" },${line#,\[}" || exit 1