2024-03-28 21:40:01 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
2024-07-14 11:38:44 +00:00
|
|
|
# - Description: A dwmblocks script to print the network 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-14 11:38:44 +00:00
|
|
|
# Check Ethernet connection
|
|
|
|
ethernet_state=$(nmcli dev | grep ethernet | awk '{print $3}')
|
2024-03-28 21:40:01 +00:00
|
|
|
|
2024-07-14 11:38:44 +00:00
|
|
|
# Check Wi-Fi connection
|
|
|
|
wifi_info=$(nmcli -t -f DEVICE,TYPE,STATE,CONNECTION dev | grep wifi)
|
|
|
|
constate=$(echo "$wifi_info" | awk -F: '{print $3}')
|
|
|
|
currentwfi=$(echo "$wifi_info" | awk -F: '{print $4}')
|
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
|
|
|
|
echo "$icon$currentwfi"
|
|
|
|
else
|
|
|
|
echo " " # just in case if nmcli isn't available or something weird is happening
|
|
|
|
fi
|