diff --git a/configs/shell/zsh/.scripts/nmcli.sh b/configs/shell/zsh/.scripts/nmcli.sh new file mode 100755 index 0000000..0e9f1db --- /dev/null +++ b/configs/shell/zsh/.scripts/nmcli.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +source ~/.scripts/utils/main.sh + +list_wifi_networks() { + echo "Available Wi-Fi Networks:" + nmcli dev wifi list +} + +connect_to_wifi() { + echo "Enter the name (SSID) of the Wi-Fi network you want to connect to:" + read ssid + + echo "Enter the password for the Wi-Fi network:" + read -s password + + sudo nmcli dev wifi connect "$ssid" password "$password" +} + +list_wifi_networks + +if ask_prompt "Do you want to connect to a Wi-Fi network ?"; then + connect_to_wifi +else + echo "No network connection requested. Exiting." +fi diff --git a/configs/shell/zsh/.scripts/utils/main.sh b/configs/shell/zsh/.scripts/utils/main.sh new file mode 100755 index 0000000..eee75ab --- /dev/null +++ b/configs/shell/zsh/.scripts/utils/main.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +check_sudo() { + if [ "$(id -u)" != 0 ]; then + echo "Please run the script with sudo." + exit 1 + fi +} + +ask_prompt() { + local question="$1" + while true; do + read -p "$question (Y/N): " choice + case "$choice" in + [Yy]) return 0 ;; + [Nn]) return 1 ;; + *) echo "Please enter Y or N." ;; + esac + done +}