2024-03-28 21:40:01 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
2024-07-15 19:11:54 +00:00
|
|
|
# - Description: A dwmblocks script to print the wifi status
|
2024-03-28 21:40:01 +00:00
|
|
|
# - Dependencies: dwm, dwmblocks, nmcli
|
|
|
|
|
|
|
|
#####
|
|
|
|
## This function gets the wifi signal strength from nmcli and then converts
|
|
|
|
## it from dBm to values from 1 to 4
|
|
|
|
#####
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-07-15 19:11:54 +00:00
|
|
|
# this variable will store the current state of the connection (connected or
|
|
|
|
# disconnected)
|
|
|
|
constate=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f3 | head -1)
|
|
|
|
|
|
|
|
# this variable will store the name of the wifi network that the computer is
|
|
|
|
# currently connected to
|
|
|
|
currentwfi=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f4 | head -1)
|
|
|
|
|
2024-07-14 11:38:44 +00:00
|
|
|
# Check Ethernet connection
|
2024-08-05 19:19:42 +00:00
|
|
|
ethernet_state=$(nmcli dev | grep ethernet | awk '{print $3}' | head -n 1)
|
2024-03-28 21:40:01 +00:00
|
|
|
|
2024-07-14 11:38:44 +00:00
|
|
|
if [ "$ethernet_state" = "connected" ]; then
|
|
|
|
echo " Ethernet "
|
|
|
|
elif [ "$constate" = "disconnected" ]; then # if the computer is disconnected
|
2024-03-28 21:40:01 +00:00
|
|
|
echo " "
|
|
|
|
elif [ "$constate" = "connected" ]; then # if it's connected
|
|
|
|
strength=$(get_wifi_strength)
|
|
|
|
case "$strength" in
|
|
|
|
"1") icon=" " ;;
|
|
|
|
"2") icon=" " ;;
|
|
|
|
"3") icon=" " ;;
|
|
|
|
"4") icon=" " ;;
|
|
|
|
esac
|
2024-08-05 19:19:42 +00:00
|
|
|
echo "$icon$currentwfi "
|
2024-03-28 21:40:01 +00:00
|
|
|
else
|
|
|
|
echo " " # just in case if nmcli isn't available or something weird is happening
|
|
|
|
fi
|