improve bar with ip addr and battery status
authorMart Lubbers <mart@martlubbers.net>
Fri, 16 Nov 2018 09:34:30 +0000 (10:34 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 16 Nov 2018 09:34:33 +0000 (10:34 +0100)
x/.local/bin/bar

index 459235d..f210c49 100755 (executable)
@@ -1,19 +1,21 @@
 #!/bin/sh
-batprefix=/sys/class/power_supply/BAT0
-if [ -f $batprefix/charge_full -a -f $batprefix/charge_now ]; then
-       bat="⚡$(echo $(cat $batprefix/charge_now)*100/$(cat $batprefix/charge_full) | bc)% | "
-fi
+for f in /sys/class/power_supply/BAT*/uevent; do
+       eval $(grep -v " " "$f")
+       bat="$bat⚡$((POWER_SUPPLY_CHARGE_NOW*100/POWER_SUPPLY_CHARGE_FULL))% ($POWER_SUPPLY_STATUS) | "
+done
 
-if ip -br a | grep -q '^wlp'; then
-       wlan="$(/sbin/iwconfig 2>/dev/null | grep -oP '(?<=ESSID:\").*(?=\")')"
-       if [ -z "$wlan" ]; then
-               wlan="Not connected"
+for int in $(ip link show | grep -Po '(?<=.: )\S+(?=:)'); do
+       if [ $(ip addr show dev $int | grep -Po "(?<=link/)\S+ ") = "ether" ]; then
+               net="$net$int: "
+               if /sbin/iwconfig $int >/dev/null 2>&1; then
+                       net="$net$(/sbin/iwconfig $int | grep -Po '(?<=ESSID:").*(?=")') "
+               fi
+               net="$net($(ip addr show dev $int | grep -Po "(?<=inet )[0-9.]+")) | "
        fi
-       wlan="W $wlan | "
-fi
+done
 
 snd="♪ $(pactl list sinks | grep -Po "(?<=Volume: front)[^%]*" | grep -o "[0-9]\?[0-9][0-9]$" | head -n 1) | "
 dsk="Dsk: $(df -h | grep '/$' | awk '{print $4"/"$2}') | "
-date="$(date +"%Y-%m-%d %H:%M:%S") "
+date="$(date +"%Y-%m-%d %H:%M") "
 
-echo "$wlan$snd$bat$dsk$date"
+echo "$net$snd$bat$dsk$date"