Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ikr7
Last active October 20, 2018 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikr7/a7c3d74294851ba869413932795c3d8c to your computer and use it in GitHub Desktop.
Save ikr7/a7c3d74294851ba869413932795c3d8c to your computer and use it in GitHub Desktop.
#!/bin/bash
IFNAME="wlp36s0"
if [ "$1" = "off" ]; then
nmcli device disconnect $IFNAME
exit 0
fi
if [ "$1" = "on" ]; then
nmcli device connect $IFNAME
exit 0
fi
if [ "$1" = "select" ]; then
SSID=$(nmcli device wifi list ifname $IFNAME | tail -n +2 | peco --prompt "Select SSID to connect" | cut -f 9 -d " ")
if [ "$SSID" = "" ]; then
echo "No SSID selected."
exit 1
fi
read -p "Enter password for $SSID : " -s PASS
echo ""
echo "Connecting..."
nmcli device wifi connect $SSID ifname $IFNAME password $PASS
exit 0
fi
echo "Invalid command '$1'"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment