summaryrefslogtreecommitdiff
path: root/.local/bin/waybar-vpn
blob: 008e74331d34f23e588caf626db9fc61793d7984 (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
#!/bin/sh

# first user argument
cmd="$1"

case "$cmd" in
	connect)
		# TODO: handle root permission password input
		if [ -n $(type "nmcli") ]; then
			nmcli connection show --active \
				rg -i 'wireguard'
		fi
		;;
	disconnect)
		# `wg-quick` requires root permission to disconnect
		# don't have the solution right now
		;;
	status)
		vpn=$(nmcli connection show --active | rg -i 'wireguard' | awk '{print $1}')
		if [ -n "$vpn" ]; then
			printf "{\"text\": \"$vpn\", \"class\": \"wireguard\", \"alt\": \"disconnected\" }\n"
		else
			printf "{\"text\": \"DC'D\", \"class\": \"wireguard\", \"alt\": \"disconnected\" }\n"
		fi
		;;
	*)
		# print usage if not used with any of the below three commands
		echo -e "Usage: %s {status|connect|disconnect}\n"
		exit 1
		;;
esac