/
rofi-wifi
executable file
·72 lines (66 loc) · 2.56 KB
/
rofi-wifi
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
#!/bin/sh
# Wifi selection menu with rofi
if [ -z "${ROFI_OUTSIDE}" ]; then
yoffset=$(( $(xrdb -query | sed -n 's/^Xft.dpi:\t\([0-9]*\)$/\1/p')*20/96 ))
exec rofi -show-icons -no-custom -modi m:$0 -show m -location 3 -yoffset $yoffset
fi
case $ROFI_RETV in
0)
# Prompt
printf "\00prompt\037wifi\n"
printf "\00markup-rows\037true\n"
case $(nmcli radio wifi) in
enabled)
printf "Turn wifi off\00info\037off\n"
printf "Scan wifi networks...\00info\037rescan\n"
;;
disabled)
printf "Turn wifi on\00info\037on\n"
;;
esac
nmcli -f IN-USE,SSID,BSSID,SECURITY,FREQ,SIGNAL -m multiline device wifi list --rescan no \
| sed -e 's/&/\&/g' -e 's/</\</g' \
| awk -F': *' '{
property=$1;
value=gensub(property ": *", "", 1);
p[property]=value;
}
($1 == "SIGNAL") {
if (p["IN-USE"] == "*") {
printf("\00message\x1fConnected to <i>%s</i> (%s, %s, %s%%)\n",
p["SSID"], p["FREQ"], p["SECURITY"], p["SIGNAL"]);
} else {
printf("%s (<i><small>%s, %s</small></i>)",
p["SSID"], p["FREQ"], p["SECURITY"]);
signal=p["SIGNAL"]
printf("\00info\x1f%s\x1ficon\x1fnm-signal-%s%s\n",
p["BSSID"],
(signal > 75)?"100":\
(signal > 50)?"75":\
(signal > 25)?"50":\
"00",
(p["SECURITY"] == "--")?"":"-secure");
}
}'
;;
1)
case ${ROFI_INFO} in
rescan)
>/dev/null nmcli device wifi list --rescan yes
;;
on)
>&2 nmcli radio wifi on
>/dev/null nmcli device wifi list --rescan yes
;;
off)
>&2 nmcli radio wifi off
;;
*)
>&2 nmcli -w 0 device wifi connect ${ROFI_INFO}
exit 0
;;
esac
export ROFI_RETV=0
exec $0
;;
esac