Skip to content

Commit 46ccb08

Browse files
authored
Merge pull request vivien#306 from skidnik/master
nm-vpn: use interface type for status, add colors, add INIT status.
2 parents e760a10 + 71a9be1 commit 46ccb08

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

nm-vpn/README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@ Parses output from `nmcli` to show the current connected VPN name/status
1515

1616
# Usage
1717

18-
`nm-vpn` gets active connection info from `nmcli` for interface `tun0`.
19-
A VPN connection in NetworkManager is established only when `tun0` is
20-
active, thus the blocklet’s response time depends on how long it takes
21-
to connect.
18+
`nm-vpn` gets active connection info from `nmcli`, looks for interface type `tun`, `tap`, `vpn`. A VPN connection is treated as established only when `tun`|`tap` is present, when it's not and a `vpn` connection is listed as active it is treated as initializing.
19+
20+
# Tunables
21+
22+
`init_color` - color used for marking a connection in initializing state, default is '#FFFF00'
23+
24+
`on_color` - color used for marking a connection in established state, default is '#00FF00'
2225

2326
## Output
2427

25-
When `tun0` is active, `nm-vpn` will print in the following form:
26-
- Full: `VPN: "Name"`
28+
When `tun`|`tap` is active, `nm-vpn` will print in the following form:
29+
- Full: `VPN Name`
2730
- Short: `ON`
31+
- Color will be set to `on_color` value
2832

29-
In addition, each form will be coloured green (“\#00FF00”).
33+
When `tun`|`tap` in not active, `nm-vpn` will print in the following form:
34+
- Full: `VPN Name`
35+
- Short: `INIT`
36+
- Color will be set to `init_color` value
3037

3138
# Config
3239

3340
``` ini
3441
[nm-vpn]
35-
label=VPN:
42+
#init_color=#FFFF00
43+
#on_color=#00FF00
44+
label=VPN:
3645
interval=5
3746
```

nm-vpn/i3blocks.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[nm-vpn]
2-
label=VPN:
2+
#init_color=#FFFF00
3+
#on_color=#00FF00
4+
label=VPN:
35
interval=5
46

57
# vim: syntax=dosini

nm-vpn/nm-vpn

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
#!/bin/sh
2+
init_color=${init_color:-#FFFF00}
3+
on_color=${on_color:-#00FF00}
4+
export init_color on_color
25
nmcli -t connection show --active | awk -F ':' '
3-
/tun0/{vpn="ON"} /vpn/{name=$1}
4-
END{if(vpn) printf("%s\n%s\n%s\n", name, vpn, "#00FF00")}'
6+
BEGIN {
7+
init_color=ENVIRON["init_color"]
8+
on_color=ENVIRON["on_color"]
9+
}
10+
$3=="vpn" {
11+
name=$1
12+
status="INIT"
13+
color=init_color
14+
}
15+
$3=="tun" || ($4~/^tap/ || $3~/^tap/) {
16+
status="ON"
17+
color=on_color
18+
}
19+
END {if(status) printf("%s\n%s\n%s\n", name, status, color)}'

0 commit comments

Comments
 (0)