Created
October 21, 2023 09:30
-
-
Save naranyala/391ddf96a9820af59576a9b71ab2dcb8 to your computer and use it in GitHub Desktop.
rofi launcher feature to connect wifi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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