1
0
Fork 0
dot/.local/bin/fuzzel_nmcli.sh

30 lines
828 B
Bash
Executable File

#!/bin/sh
bssid="$(nmcli --colors=no -f BSSID,IN-USE,SSID,BARS device wifi list\
| tail -n+2\
| fuzzel -d -p "connect > "\
| cut -d" " -f1)"
[ -z "$bssid" ] && return
ssid="$(nmcli -g SSID device wifi list bssid "$bssid" --rescan no)"
if nmcli -t connection show "$ssid" >/dev/null 2>&1; then
if nmcli device wifi connect "$bssid" 2>&1; then
exec notify-send "Connected to $ssid."
else
exec notify-send "Could not connect to $ssid."
fi
else
security="$(nmcli -g SECURITY device wifi list bssid "$bssid" --rescan no)"
if [ "$security" = "WPA2" ] || [ "$security" = "WEP" ]; then
password="$(fuzzel -d --password -p "password > ")"
fi
if nmcli device wifi connect "$bssid" password "$password" 2>&1; then
exec notify-send "Connected to $ssid."
else
exec notify-send "Could not connect to $ssid."
fi
fi