2022-02-24 15:46:22 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# choose a wifi signal in range and try to connect to it
|
|
|
|
|
|
|
|
verb=0
|
|
|
|
|
|
|
|
title="Wifi Selector"
|
|
|
|
id=""
|
|
|
|
notify () {
|
|
|
|
if [ -z "$id" ] ; then
|
|
|
|
id="$(dunstify -p "$title" "$@")"
|
|
|
|
else
|
|
|
|
dunstify -r "$id" "$title" "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nmcli radio wifi | grep disabled > /dev/null ) ; then
|
|
|
|
notify "Turning on"
|
|
|
|
nmcli radio wifi on
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
notify "Scanning networks in range..."
|
|
|
|
nmcli device wifi rescan
|
|
|
|
|
2022-02-25 12:34:57 +00:00
|
|
|
ssid="$(nmcli -f IN-USE,SSID,BARS d wifi list | dmenu -l 8)"
|
|
|
|
ssid="$(echo "${ssid:2:-5}" | sed 's/^ *//g' | sed 's/ *$//g')"
|
2022-02-24 15:46:22 +00:00
|
|
|
|
2022-02-25 12:34:57 +00:00
|
|
|
# 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"
|
2022-02-24 15:46:22 +00:00
|
|
|
[ -z "$ssid" ] && notify "No SSID selected" && exit 1
|
|
|
|
|
|
|
|
notify "Connecting to $ssid"
|
2022-02-25 12:34:57 +00:00
|
|
|
out="$(nmcli d wifi connect "$ssid" 2>&1 | grep -i error)"
|
2022-02-24 15:46:22 +00:00
|
|
|
res="$?"
|
2022-02-25 12:34:57 +00:00
|
|
|
[ -z "$out" ] && notify "Connected :)" || notify "Error connecting :(\n$out"
|