summaryrefslogtreecommitdiff
path: root/.config/wmii-hg/rbar_wifi
blob: e740777412258a7692ea9fd247c8961643d86059 (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
#!/usr/bin/env bash

update() {
	local iface=wlp2s0

	local id
	id=$1
	setup_trap "$id"
	while true; do
		IFS=$'\n'
		lines=($(
			iwdata "$iface" | sed -rn 's@^(ESSID|Link Quality)=@@p'
			ifdata -pa "$iface"
		))
		IFS='|'
		echo "label ${lines[*]}" | write "$id"
		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"