Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created October 21, 2023 09:30
Show Gist options
  • Save naranyala/391ddf96a9820af59576a9b71ab2dcb8 to your computer and use it in GitHub Desktop.
Save naranyala/391ddf96a9820af59576a9b71ab2dcb8 to your computer and use it in GitHub Desktop.
rofi launcher feature to connect wifi
#!/bin/bash
# Network manager script for Awesome WM using Rofi and nmcli
options="Connect to Wi-Fi\nDisconnect\nEdit Connections\nQuit"
choice=$(echo -e "$options" | rofi -dmenu -p "Network Manager")
case "$choice" in
"Connect to Wi-Fi")
# Display a list of available Wi-Fi networks with SSID names and numbers
wifi_list=$(nmcli -t -f in-use,ssid dev wifi list | awk -F: '{print NR, $2}')
# Show the list in Rofi and prompt the user to select a network by number
selected_ssid=$(echo "$wifi_list" | rofi -dmenu -p "Select a Wi-Fi network:" | awk '{print $2}')
# Prompt the user to enter the password for the selected SSID securely (password is not shown while typing)
read -s -p "Enter the Wi-Fi password for $selected_ssid: " wifi_password
# Connect to the selected Wi-Fi network using nmcli
nmcli dev wifi connect "$selected_ssid" password "$wifi_password"
notify-send "Connect to Wi-Fi >> $selected_ssid ..."
echo "Connect to Wi-Fi >> $selected_ssid..."
;;
"Disconnect")
connection=$(nmcli -t -f NAME,TYPE con show --active | rofi -dmenu -p "Disconnect:")
if [ -n "$connection" ]; then
nmcli con down "$connection"
fi
;;
"Edit Connections")
nm-connection-editor
;;
"Quit")
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment