configuration form the arch linux stored
This commit is contained in:
63
polybar/scripts/wlan_format.sh
Executable file
63
polybar/scripts/wlan_format.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Toggle file for switching between SSID and signal strength
|
||||
TOGGLE_FILE="$HOME/.toggle_wlan_label"
|
||||
|
||||
# Function to check Ethernet connection
|
||||
check_ethernet() {
|
||||
if ip a show enp8s0 | grep -q "state UP"; then
|
||||
echo "E"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to get WiFi signal strength as a percentage
|
||||
get_signal_strength() {
|
||||
local strength=$(iwconfig wlan0 2>/dev/null | grep 'Link Quality' | awk -F'=' '{print $2}' | awk '{print $1}')
|
||||
if [ -z "$strength" ]; then
|
||||
echo 0
|
||||
return
|
||||
fi
|
||||
local level=$(echo "$strength" | cut -d'/' -f1)
|
||||
local max=$(echo "$strength" | cut -d'/' -f2)
|
||||
local percent=$(( ($level * 100) / $max ))
|
||||
echo $percent
|
||||
}
|
||||
|
||||
# Check Ethernet connection first
|
||||
if check_ethernet; then
|
||||
echo "E"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if the toggle file exists
|
||||
if [ -f "$TOGGLE_FILE" ]; then
|
||||
# Display SSID if connected
|
||||
essid=$(iwgetid -r)
|
||||
if [ -z "$essid" ]; then
|
||||
# Display disconnected icon if not connected
|
||||
echo "%{A1:~/.config/polybar/scripts/toggle_module_label.sh wlan:}%{A}"
|
||||
elif [ "$essid" == "Hacker" ]; then
|
||||
# Display "H" if connected to "Hacker"
|
||||
echo "H"
|
||||
else
|
||||
# Display SSID
|
||||
echo "%{A1:~/.config/polybar/scripts/toggle_module_label.sh wlan:} $essid %{A}"
|
||||
fi
|
||||
else
|
||||
# Display signal strength icon
|
||||
strength=$(get_signal_strength)
|
||||
icon="" # Default icon for no signal
|
||||
if [ "$strength" -ge 80 ]; then
|
||||
icon="" # Signal 4
|
||||
elif [ "$strength" -ge 60 ]; then
|
||||
icon="" # Signal 3
|
||||
elif [ "$strength" -ge 40 ]; then
|
||||
icon="" # Signal 2
|
||||
elif [ "$strength" -ge 20 ]; then
|
||||
icon="" # Signal 1
|
||||
fi
|
||||
echo "%{A1:~/.config/polybar/scripts/toggle_module_label.sh wlan:} $icon %{A}"
|
||||
fi
|
||||
Reference in New Issue
Block a user