49 lines
1.5 KiB
Bash
Executable file
49 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
|
# - Description: A dwmblocks script to print the network status
|
|
# - 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
|
|
}
|
|
|
|
# Check Ethernet connection
|
|
ethernet_state=$(nmcli dev | grep ethernet | awk '{print $3}')
|
|
|
|
# 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}')
|
|
|
|
if [ "$ethernet_state" = "connected" ]; then
|
|
echo " Ethernet "
|
|
elif [ "$constate" = "disconnected" ]; then # if the computer is disconnected
|
|
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
|