From 3fee9a288c8671027370f1dc588f5bc1612302d5 Mon Sep 17 00:00:00 2001 From: hesam-init Date: Thu, 28 Mar 2024 12:04:31 +0330 Subject: [PATCH] feat: nmcli shell --- configs/shell/zsh/.scripts/nmcli.sh | 26 ++++++++++++++++++++++++ configs/shell/zsh/.scripts/utils/main.sh | 20 ++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 configs/shell/zsh/.scripts/nmcli.sh create mode 100755 configs/shell/zsh/.scripts/utils/main.sh 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 +}