summaryrefslogtreecommitdiff
path: root/scripts/wifi.sh
blob: 51262c65b31155d7f6d5d2c28decb7f0739353f7 (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
#!/bin/bash
# dotfiles -- scripts/wifi.sh
# author: johannst

if="${BLOCK_INSTANCE:-wlp3s0}"
[[ ! -d /sys/class/net/${if} ]] && exit 0

show_ap_mac=0
show_ap_quality=0
show_ap_name=0
for arg in "$@"; do
	case $arg in
		-aq | --ap_quality) show_ap_quality=1
			;;
		-am | --ap_mac) show_ap_mac=1
			;;
		-an | --ap_name) show_ap_name=1
			;;
		*) # ignore unknown
			;;
	esac
done

AP_NAME=$(iwgetid -r $if)
AP_MAC=$(iwgetid -a $if | sed 's/.*\(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\{2\}\).*/\1/')
AP_QUALITY=$(printf '%3s' $(grep $if /proc/net/wireless | awk '{ print int($3 * 100 / 70) }'))%

# first ipv4 addr
IP_ADDR=$(ip address show $if | grep 'inet ' | sed 's/\s\+inet \([0-9.]\+\)\/.*/\1/')

OUT="$IP_ADDR"
if [[ $show_ap_name == 1 && $show_ap_quality == 1 ]]; then
	OUT="$OUT ($AP_NAME $AP_QUALITY)"
elif [[ $show_ap_name == 1 ]]; then
	OUT="$OUT ($AP_NAME)"
elif [[ $show_ap_quality == 1 ]]; then
	OUT="$OUT ($AP_QUALITY)"
fi
[[ $show_ap_mac == 1 ]] && OUT="$OUT $AP_MAC"

echo "$OUT"