diff --git a/bin/qrwifi b/bin/qrwifi index 2556529..8b2565b 100755 --- a/bin/qrwifi +++ b/bin/qrwifi @@ -1,5 +1,18 @@ #!/bin/sh -ssid="${1:-}" +DMENU="$(which dmenu 2>/dev/null)" +if [ -z "$DMENU" ]; then + DMENU="$(which rofi) -dmenu" +fi + +if [ "${1:-}" = -i ] || [ "${1:-}" = --interactive ]; then + ssid="$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf | sed -n '/^[\t ]*ssid="[^"][^"]*"$/{:findpsk;N;/}/d;/\n[\t ]*psk=/!b findpsk;s/^\(\n\|.\)*[\t ]*ssid="\([^"]*\)"\(\n\|.\)*$/\2/p; }' | $DMENU)" + if [ -z "$ssid" ]; then + exit 1 + fi +else + ssid="${1:-}" +fi + if [ -z "$ssid" ]; then ssid="$(wpa_cli status | rg -o --replace='$1' '^ssid=(.*)$')" fi