commit 0dc9de9de7b8d1cf95fdc1d34e1f51c7fefd60bc
parent 9349d2e5ecfc6760d78f39a270b8931fe79e0c09
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 16 Jun 2025 08:08:11 +0900
refactor network
Diffstat:
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/bin/dwm_status b/bin/dwm_status
@@ -20,8 +20,32 @@ cpu=" CPU $(uptime | sed 's/.*load averages: \(.*\)/\1/' | cut -d, -f1) "$(print
tmp=" TMP $(sysctl -n hw.sensors.cpu0.temp0 | cut -d'.' -f1) |"
-eth=$(ifconfig em0 | awk '/active/{printf "ETH "}')
-wifi=$(ifconfig iwn0 | awk '/active/{printf "WIFI "}/no network/{printf "down:"}/join/{printf "%s %s\n", $3, $8}')
+if=$(ifconfig | grep '^[^ ]*:' | sed 's/:.*//')
+eif="em re"
+wif="iwx iwm iwn"
+for i in $if
+do
+ ii=${i%%[0-9]*}
+ if echo $eif | grep -q $ii; then
+ eth="$i"
+ fi
+ if echo $wif | grep -q $ii; then
+ wifi="$i"
+ fi
+done
+
+echo $eth >&2
+echo $wifi >&2
+
+if [ -n "eth" ]; then
+ eth=$(ifconfig $eth | awk '/active/{printf "ETH "}')
+fi
+if [ -n "wifi" ]; then
+ wifi=$(ifconfig $wifi | awk '
+ /active/{printf "WIFI "}
+ /no network/{printf "down:"}
+ /ieee80211:/{printf "%s %s\n", $3, $8}')
+fi
nw=" $eth$wifi"
printf "%s%s%s%s%s%s\n" "$date" "$volume" "$bat" "$cpu" "$tmp" "$nw"