-
Notifications
You must be signed in to change notification settings - Fork 3
/
wireguard-rofi.sh
executable file
·54 lines (47 loc) · 1.15 KB
/
wireguard-rofi.sh
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
#!/usr/bin/env bash
# WireGuard custom menu script to manage NetworkManager WireGuard connections using rofi
# install to the same directory as wireguard.sh
# example usage with rofi: rofi -modi 'WireGuard:~/.config/rofi/wireguard-rofi.sh' -show WireGuard
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
if [[ $# != 0 ]]
then
if [[ "$@" == "quit" ]]
then
exit 0
elif [[ "$1" != "reload" ]]
then
connection=$(echo $1 | cut -d: -f1)
message="$($SCRIPT_DIR/wireguard.sh toggle $connection)"
if command -v notify-send >/dev/null 2>&1; then
notify-send "wireguard" "$message"
fi
exit 0
fi
fi
active=-1
urgent=-1
while read -r state connection IP
do
if [[ "$state" == "connected:" ]]
then
active=$(($active+1))
elif [[ "$state" == "available:" ]]
then
urgent=$(($urgent+1))
fi
if [[ "$IP" != "" ]]
then
connection="$connection [$IP]"
fi
echo -en "$connection\0icon\x1fwireguard\n"
done < <($SCRIPT_DIR/wireguard.sh menu)
if [[ $active -ge 0 ]]
then
echo -en "\0active\x1f0-$active\n"
fi
if [[ $urgent -ge 0 ]]
then
echo -en "\0urgent\x1f$(($active+1))-$(($active+1+$urgent))\n"
fi
echo "reload"
echo "quit"