Skip to content

Instantly share code, notes, and snippets.

@Kabouik
Forked from guyzmo/nm-wifi-fzf.sh
Created September 6, 2022 15:22
Show Gist options
  • Save Kabouik/a114d97bcfbdc2db5dd939f7320cb8e6 to your computer and use it in GitHub Desktop.
Save Kabouik/a114d97bcfbdc2db5dd939f7320cb8e6 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment