auto refresh netctrl

This commit is contained in:
speedie 2023-05-07 16:39:44 +02:00
parent 6834e34b9d
commit 7d5491538b

View file

@ -25,15 +25,23 @@ getdevice() {
#[ -z "$seldevice" ] && exit 0
}
listentries() {
printf "%s\n\nDisconnect\nExit\n" "$(iwctl station "$seldevice" get-networks | sed -n 6,20p | sed "s|>||g" | awk '{ print $1 }')" | sed "s| |No networks found|g" > /tmp/netctrl-file
sleep 3
listentries
}
# connect to wifi
connectwifi() {
# if args aren't disconnect, scan for networks
# if it is disconnect, disconnect
if [ "$INARGS" != "disconnect" ]; then
iwctl station $seldevice scan
network="$(printf "%s\n\nRefresh\nDisconnect\nExit" \
"$(iwctl station "$seldevice" get-networks | sed -n 6,20p | sed "s|>||g" | awk '{ print $1 }')" | sed "s| |No networks found|g" | \
$RUNLAUNCHER -l 10 -g 1 -p "Select a network to connect to" | sed "s|||g")"
rm -f /tmp/netctrl-file
listentries &
network="$($RUNLAUNCHER -lf /tmp/netctrl-file -l 10 -g 1 -p "Select a network to connect to" | sed "s|||g")"
# check output
case "$network" in
@ -41,14 +49,13 @@ connectwifi() {
"No networks found") exit 0 ;;
"Disconnect") disconnect=true ;;
"Exit") exit 0 ;;
"Refresh") getdevice "$@" && connectwifi "$@" ;;
esac
else
disconnect=true
fi
if [ "$disconnect" != "true" ]; then
iwctl station "$seldevice" get-networks | grep "$network" > /dev/null || exit 1
iwctl station "$seldevice" get-networks | grep -q "$network" || exit 1
connect_pass() {
iwctl station "$seldevice" disconnect