fix(waybar/network): détecter l'interface active via la route par défaut

Remplace la liste codée en dur d'interfaces (enp7s0, wlp8s0…) par
'ip route get 1.1.1.1' qui retourne l'interface réellement utilisée,
portable sur n'importe quelle machine sans configuration.
This commit is contained in:
Tetardtek
2026-02-23 22:16:41 +01:00
parent 0ba6bbd181
commit 59c39260d1

View File

@@ -3,19 +3,17 @@
STATE_FILE="/tmp/waybar_net_state" STATE_FILE="/tmp/waybar_net_state"
# Détecter l'interface active # Détecter l'interface active via la route par défaut (portable sur tous les PC)
IFACE="" IFACE=$(ip route get 1.1.1.1 2>/dev/null \
for candidate in enp7s0 enp6s0 eth0; do | awk '/dev/{for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}' \
if [[ -d "/sys/class/net/$candidate" && "$(cat /sys/class/net/$candidate/operstate 2>/dev/null)" == "up" ]]; then | head -1)
IFACE="$candidate"; TYPE="eth"; break
if [[ -n "$IFACE" ]]; then
if [[ -d "/sys/class/net/$IFACE/wireless" || -d "/sys/class/net/$IFACE/phy80211" ]]; then
TYPE="wifi"
else
TYPE="eth"
fi fi
done
if [[ -z "$IFACE" ]]; then
for candidate in wlp8s0 wlp0s20f3 wlan0; do
if [[ -d "/sys/class/net/$candidate" && "$(cat /sys/class/net/$candidate/operstate 2>/dev/null)" == "up" ]]; then
IFACE="$candidate"; TYPE="wifi"; break
fi
done
fi fi
if [[ -z "$IFACE" ]]; then if [[ -z "$IFACE" ]]; then