Nicer wifi script

This commit is contained in:
Adrian Amaglio 2022-02-25 13:34:57 +01:00
parent a406f96999
commit 216aa488d3

View File

@ -22,12 +22,17 @@ fi
notify "Scanning networks in range..."
nmcli device wifi rescan
ssid=$(nmcli -f IN-USE,SSID,BARS d wifi list | dmenu -l 8 | tr -s '*' ' ' | rev | cut -d ' ' -f 3- | rev | cut -d ' ' -f 2-)
ssid="$(nmcli -f IN-USE,SSID,BARS d wifi list | dmenu -l 8)"
ssid="$(echo "${ssid:2:-5}" | sed 's/^ *//g' | sed 's/ *$//g')"
[ $verb -gt 0 ] && echo ssid: $ssid
# We get a clean version of SSIDs. It is a fix to connect to wifis that begin or end with spaces
ssid="$(nmcli -f SSID -m multiline -t -c no d wifi list | grep -F "$ssid")"
ssid="${ssid:5}"
[ $verb -gt 0 ] && echo "ssid: $ssid"
[ -z "$ssid" ] && notify "No SSID selected" && exit 1
notify "Connecting to $ssid"
out="$(nmcli d wifi connect "$ssid" | grep -i error)"
out="$(nmcli d wifi connect "$ssid" 2>&1 | grep -i error)"
res="$?"
[ "$res" -ne 0 ] && notify "Connected :)" || notify "Error connecting :(\n$out"
[ -z "$out" ] && notify "Connected :)" || notify "Error connecting :(\n$out"