34 lines
795 B
Plaintext
34 lines
795 B
Plaintext
|
#!/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
|
||
|
|
||
|
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-)
|
||
|
|
||
|
[ $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)"
|
||
|
res="$?"
|
||
|
[ "$res" -ne 0 ] && notify "Connected :)" || notify "Error connecting :(\n$out"
|