Skip to content

Instantly share code, notes, and snippets.

@ikr7 ikr7/wifi.sh
Last active Oct 20, 2018

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.