ark/users/modules/eww/scripts/net

41 lines
909 B
Plaintext
Raw Normal View History

2022-09-14 15:35:52 +03:00
#!/usr/bin/env bash
2022-10-22 23:54:44 +03:00
toggle() {
status=$(rfkill -J | jq -r '.rfkilldevices[] | select(.type == "wlan") | .soft' | head -1)
2022-09-14 15:35:52 +03:00
2022-10-22 23:54:44 +03:00
if [ "$status" = "unblocked" ]; then
rfkill block wlan
2022-09-14 15:35:52 +03:00
else
2022-10-22 23:54:44 +03:00
rfkill unblock wlan
2022-09-14 15:35:52 +03:00
fi
2022-10-22 23:54:44 +03:00
}
if [ "$1" = "toggle" ]; then
toggle
else
while true; do
status=$(nmcli g | tail -n 1 | awk '{print $1}')
signal=$(nmcli -f in-use,signal dev wifi | rg "\*" | awk '{ print $2 }')
essid=$(nmcli -t -f NAME connection show --active | head -n1)
icons=("󰤯" "󰤟" "󰤢" "󰤥" "󰤨")
if [ "$status" = "disconnected" ] ; then
icon=""
color="#988ba2"
else
level=$(awk -v n="$signal" 'BEGIN{print int((n-1)/20)}')
if [ "$level" -gt 4 ]; then
level=4
fi
icon=${icons[$level]}
color="#cba6f7"
fi
2022-09-14 15:35:52 +03:00
2022-10-22 23:54:44 +03:00
echo '{ "essid": "'"$essid"'", "icon": "'"$icon"'", "color": "'"$color"'" }'
2022-09-14 15:35:52 +03:00
2022-10-22 23:54:44 +03:00
sleep 3
done
fi