summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-06-11 19:51:44 -0400
committerDavid Robillard <d@drobilla.net>2016-09-05 22:31:42 -0400
commit83830a2b56f298cd82faa9cdc17acd6ddbb0a77c (patch)
treebd98a494e10e131c079c3e8a26116c79a8f4b48a
parentcfe669147437399280ba72a5eaeccb6f565b7a9e (diff)
downloaddotfiles-83830a2b56f298cd82faa9cdc17acd6ddbb0a77c.tar.gz
dotfiles-83830a2b56f298cd82faa9cdc17acd6ddbb0a77c.tar.bz2
dotfiles-83830a2b56f298cd82faa9cdc17acd6ddbb0a77c.zip
Fix network status if no interfaces are present
-rwxr-xr-xbspwm/panel48
1 files changed, 29 insertions, 19 deletions
diff --git a/bspwm/panel b/bspwm/panel
index a16448d..24bf33a 100755
--- a/bspwm/panel
+++ b/bspwm/panel
@@ -59,28 +59,38 @@ done &
# Network throughput
while :; do
- net_info=$(
- ip -4 -o addr show | grep -v ' lo ' |
- while read line; do
- iface=$(echo $line | cut -d ' ' -f 2);
- addr=$(echo $line | cut -d ' ' -f 4 | sed 's/\/.*//');
+ net_info=$(
+ ip -4 -o addr show | grep -v ' lo ' |
+ while read line; do
+ iface=$(echo $line | cut -d ' ' -f 2);
+ # addr=$(echo $line | cut -d ' ' -f 4 | sed 's/\/.*//');
- rf=/sys/class/net/eth0/statistics/rx_bytes;
- tf=/sys/class/net/eth0/statistics/tx_bytes;
+ if [ ! -d /sys/class/net/$iface ]; then
+ sleep 1;
+ continue;
+ fi
- # Get RX and TX bytes then sleep for ~1 second
- r1=`cat $rf`;
- t1=`cat $tf`;
- sleep 1
+ rf=/sys/class/net/$iface/statistics/rx_bytes;
+ tf=/sys/class/net/$iface/statistics/tx_bytes;
- # Get RX and TX bytes and print rates in KBPS
- r2=`cat $rf`;
- t2=`cat $tf`;
- rr="$(((r2-r1)/1024))";
- tr="$(((t2-t1)/1024))";
- printf "$iface $addr %04.0f↓ %04.0f↑ " $rr $tr
- done)
- echo "N$net_info" > "$PANEL_FIFO"
+ # Get RX and TX bytes then sleep for ~1 second
+ r1=`cat $rf`;
+ t1=`cat $tf`;
+ sleep 1
+
+ # Get RX and TX bytes and print rates in KBPS
+ r2=`cat $rf`;
+ t2=`cat $tf`;
+ rr="$(((r2-r1)/1024))";
+ tr="$(((t2-t1)/1024))";
+ # printf "$iface $addr %04.0f↓ %04.0f↑ " $rr $tr
+ printf "$iface %04.0f↓ %04.0f↑ " $rr $tr
+ done)
+ if [ -z "$net_info" ]; then
+ sleep 5;
+ else
+ echo "N$net_info" > "$PANEL_FIFO"
+ fi
done &
#. ./panel_colors