Skip to content

Instantly share code, notes, and snippets.

@guyzmo
Created May 28, 2017 09:09
Show Gist options
  • Save guyzmo/146423d0cf7d3c0a46e10eeb66883905 to your computer and use it in GitHub Desktop.
Save guyzmo/146423d0cf7d3c0a46e10eeb66883905 to your computer and use it in GitHub Desktop.
Connect to Wifi networks using network manager listed by fzf
wl(){
local ssid
local conn
nmcli device wifi rescan > /dev/null
ssid=$(nmcli device wifi list | tail -n +2 | grep -v '^ *\B--\B' | fzf -m | sed 's/^ *\*//' | awk '{print $1}')
if [ "x$ssid" != "x" ]; then
# check if the SSID has already a connection setup
conn=$(nmcli con | grep "$ssid" | awk '{print $1}' | uniq)
if [ "x$conn" = "x$ssid" ]; then
echo "Please wait while switching to known network $ssid…"
# if yes, bring up that connection
nmcli con up id "$conn"
else
echo "Please wait while connecting to new network $ssid…"
# if not connect to it and ask for the password
nmcli device wifi connect "$ssid"
fi
fi
}
@emilBeBri
Copy link

very nice thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment