34 lines
923 B
Bash
Executable file
34 lines
923 B
Bash
Executable file
#!/bin/bash
|
|
|
|
get_wifi_strength() {
|
|
# Retrieves the wifi signal strength in dBm
|
|
strength=$(nmcli -t -f active,ssid,signal dev wifi | grep yes | cut -d ":" -f3)
|
|
# Converts dBm to percentage (0% to 100%)
|
|
if [ "$strength" -le 30 ]; then
|
|
echo "1"
|
|
elif [ "$strength" -le 60 ]; then
|
|
echo "2"
|
|
elif [ "$strength" -le 90 ]; then
|
|
echo "3"
|
|
else
|
|
echo "4"
|
|
fi
|
|
}
|
|
|
|
constate=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f3 | head -1)
|
|
currentwfi=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f4 | head -1)
|
|
|
|
if [ "$constate" = "disconnected" ]; then
|
|
echo " "
|
|
elif [ "$constate" = "connected" ]; then
|
|
strength=$(get_wifi_strength)
|
|
case "$strength" in
|
|
"1") icon=" " ;;
|
|
"2") icon=" " ;;
|
|
"3") icon=" " ;;
|
|
"4") icon=" " ;;
|
|
esac
|
|
echo "$icon$currentwfi"
|
|
else
|
|
echo " "
|
|
fi
|