[bin/qrwifi] Add interactive mode

to choose a saved network to share
This commit is contained in:
Midgard 2023-07-26 18:18:14 +02:00
parent f622651482
commit b83a91e303
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -1,5 +1,18 @@
#!/bin/sh #!/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 if [ -z "$ssid" ]; then
ssid="$(wpa_cli status | rg -o --replace='$1' '^ssid=(.*)$')" ssid="$(wpa_cli status | rg -o --replace='$1' '^ssid=(.*)$')"
fi fi