summaryrefslogtreecommitdiff
path: root/.local/sbin/nmgui
blob: c9f15ea9e1c92547f3ee57f487a813e2c0cc362c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh

ssid="$(
	nmcli -g SSID,RATE,BARS device wifi list \
	| gawk '
		function conncmp(i1, v1, i2, v2)
		{
			if (v1[SGNL] != v2[SGNL])
				return v2[SGNL] - v1[SGNL]	
			if (v1[RATE] != v2[RATE])
				return v2[RATE] - v1[RATE]
			if (v1[SSID] > v2[SSID])
				return +1
			if (v1[SSID] < v2[SSID])
				return -1
			return 0
		}

		BEGIN {
			FPAT = "([^:\\\\]|\\\\[:\\\\])+"

			SGNL = 1
			RATE = 2
			SSID = 3

			ICON[1] = "󰤟"
			ICON[2] = "󰤢"
			ICON[3] = "󰤥"
			ICON[4] = "󰤨"
		}

		/^:/ { next }

		$3 == "▂___" { conns[NR][SGNL] = 1 }
		$3 == "▂▄__" { conns[NR][SGNL] = 2 }
		$3 == "▂▄▆_" { conns[NR][SGNL] = 3 }
		$3 == "▂▄▆█" { conns[NR][SGNL] = 4 }

		{
			rate = substr($2, 1, index($2, " ") - 1)
			conns[NR][RATE] = rate
			conns[NR][SSID] = $1
		}

		END {
			asort(conns, conns, "conncmp")
			for (i in conns) {
				printf "%s\t%s (%s Mb/s)\n", \
					ICON[conns[i][SGNL]], conns[i][SSID], conns[i][RATE]
			}
		}
	' \
	| fuzzel -d -p 'SSID → '\
	| sed -E 's/[^\t]+\t(.*) \([0-9]+ Mb\/s\)/\1/'
)"

# nmcli connection up id "$ssid" && exit 0
nmcli device wifi connect "$ssid"
if test $? -eq 4
then
	passwd="$(fuzzel -d -l0 -P0 --password --prompt 'Password → ')" || exit 1
	nmcli device wifi connect "$ssid" password "$passwd"
fi