summaryrefslogtreecommitdiff
path: root/.config/wmii-hg/rbar_wifi
blob: c77efa53697af17cb54c4974a4adcdeef118be33 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash

in_array() {
	local needle straw haystack
	needle=$1
	haystack=("${@:2}")
	for straw in "${haystack[@]}"; do
		if [[ "$needle" = "$straw" ]]; then
			return 0
		fi
	done
	return 1
}

update() {
	local id
	id=$1
	setup_trap "${id}.*"

	while true; do
		for iface in /sys/class/net/*; do
			iface=${iface##*/}
			parts=()
			case "$iface" in
				lo|docker*|veth*)
					continue
					;;
				w*)
					IFS=$'\n'
					parts+=($(iwdata "$iface" | sed -rn 's@^(ESSID|Link Quality)=@@p'))
					;;
				*)
					:
					;;
			esac
			parts+=("$(ifdata -pa "$iface")")
			IFS='|'
			printf '%s %s\n' "$iface" "${parts[*]}"
		done | (
			ifaces=()
			while read -r iface data; do
				ifaces+=("$iface")
				printf "label %s\n" "${iface}:${data}" | write "${id}.${iface}"
			done
			for file in "${XDG_RUNTIME_DIR}"/wmii*/rbar/"${id}".*; do
				    if ! in_array "${file##*/"$id".}" "${ifaces[@]}"; then
					    rm -f -- "$file"
				    fi
			done
		)
		sleep 1
	done
}

right-click() {
	local list cur item

	list=()
	IFS=''
	while read -r line; do
		list+=("$line")
	done < <({ netctl-auto list | sort -k1.2; printf '> %s\n' 'New Network' 'Disable All' 'Enable All';} | sed 's,$,$,' | column -s '$' -t)

	cur=''
	for item in "${list[@]}"; do
		if [[ "$item" = '* '* ]]; then
			cur="$item"
		fi
	done

	IFS=$' \t\n'
	item=$(wmii9menu -i "$cur" "${list[@]}")
	case "$item" in
	'')
		# Nothing selected
		;;
	'* '*)
		# Already selected; do nothing
		;;
	'> New Network'*)
		urxvt +sb -title wifi-menu -e sudo wifi-menu
		;;
	'> Disable All'*)
		sudo netctl-auto disable-all
		;;
	'> Enable All'*)
		sudo netctl-auto enable-all
		;;
	*)
		# NB: do NOT quote $item; we need to strip whitespace
		sudo netctl-auto switch-to $item
		;;
	esac
}

. "$(dirname "$0")/rbar.sh"