dotfiles/dot_config/polybar/scripts/executable_wifi-menu.sh
punkfairie 90ca5ee74b
Update .config/packages/archgirlie
Add .config/polybar/colors.ini
Add .config/polybar/config.ini
Add .config/polybar/launch.sh
Add .config/polybar/scripts/backlight.sh
Add .config/polybar/scripts/launcher.sh
Add .config/polybar/scripts/player.sh
Add .config/polybar/scripts/powermenu.sh
Add .config/polybar/scripts/pywal.sh
Add .config/polybar/scripts/songname.sh
Add .config/polybar/scripts/wifi-menu.sh
Add .config/polybar/scripts/rofi/colors.rasi
Add .config/polybar/scripts/rofi/colors.rasi.backup
Add .config/polybar/scripts/rofi/confirm.rasi
Add .config/polybar/scripts/rofi/launcher.rasi
Add .config/polybar/scripts/rofi/message.rasi
Add .config/polybar/scripts/rofi/networkmenu.rasi
Add .config/polybar/scripts/rofi/powermenu.rasi
Add .config/polybar/scripts/rofi/styles.rasi
Add .config/polybar/scripts/scripts/checkupdates
Add .config/polybar/scripts/scripts/color-switch.sh
Add .config/polybar/scripts/scripts/colors-dark.sh
Add .config/polybar/scripts/scripts/colors-light.sh
Add .config/polybar/scripts/scripts/launcher.sh
Add .config/polybar/scripts/scripts/powermenu.sh
Add .config/polybar/scripts/scripts/pywal.sh
Add .config/polybar/scripts/scripts/random.sh
Add .config/polybar/scripts/scripts/updates.sh
Add .config/polybar/scripts/scripts/rofi/colors.rasi
Add .config/polybar/scripts/scripts/rofi/confirm.rasi
Add .config/polybar/scripts/scripts/rofi/launcher.rasi
Add .config/polybar/scripts/scripts/rofi/message.rasi
Add .config/polybar/scripts/scripts/rofi/networkmenu.rasi
Add .config/polybar/scripts/scripts/rofi/powermenu.rasi
Add .config/polybar/scripts/scripts/rofi/styles.rasi
2024-07-28 17:37:13 -07:00

39 lines
1.7 KiB
Bash

#!/usr/bin/env bash
#notify-send "Getting list of available Wi-Fi networks..."
# Get a list of available wifi connections and morph it into a nice-looking list
wifi_list=$(nmcli --fields "SECURITY,SSID" device wifi list | sed 1d | sed 's/ */ /g' | sed -E "s/WPA*.?\S/ /g" | sed "s/^--/ /g" | sed "s/ //g" | sed "/--/d")
connected=$(nmcli -fields WIFI g)
if [[ "$connected" =~ "enabled" ]]; then
toggle="󰖪 Disable Wi-Fi"
elif [[ "$connected" =~ "disabled" ]]; then
toggle="󰖩 Enable Wi-Fi"
fi
# Use rofi to select wifi network
chosen_network=$(echo -e "$toggle\n$wifi_list" | uniq -u | rofi -dmenu -i -selected-row 1 -p "Wi-Fi SSID: " -theme ~/.config/polybar/mytheme/scripts/rofi/powermenu.rasi)
# Get name of connection
read -r chosen_id <<< "${chosen_network:3}"
if [ "$chosen_network" = "" ]; then
exit
elif [ "$chosen_network" = "󰖩 Enable Wi-Fi" ]; then
nmcli radio wifi on
elif [ "$chosen_network" = "󰖪 Disable Wi-Fi" ]; then
nmcli radio wifi off
else
# Message to show when connection is activated successfully
success_message="You are now connected to the Wi-Fi network \"$chosen_id\"."
# Get saved connections
saved_connections=$(nmcli -g NAME connection)
if [[ $(echo "$saved_connections" | grep -w "$chosen_id") = "$chosen_id" ]]; then
nmcli connection up id "$chosen_id" | grep "successfully" && notify-send "Connection Established" "$success_message"
else
if [[ "$chosen_network" =~ "" ]]; then
wifi_password=$(rofi -dmenu -p "Password: " -theme ~/.config/polybar/colorblocks/scripts/rofi/launcher.rasi)
fi
nmcli device wifi connect "$chosen_id" password "$wifi_password" | grep "successfully" && notify-send "Connection Established" "$success_message"
fi
fi