1
0
mirror of https://github.com/alrayyes/dotfiles/ synced 2023-11-14 15:56:30 +00:00

split wireguard status into individual widgets

This commit is contained in:
Ryan Kes 2020-03-12 22:09:11 +01:00
parent 3e153b8976
commit 82550fdc9b
3 changed files with 26 additions and 28 deletions

View File

@ -1,21 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
interfaces="$(sudo wg show | grep interface | awk -F ' ' '{print $2}')" updown="$(sudo wg show $1 2> /dev/null)"
interfaces=(${interfaces// / }) if [ "$updown" ]; then
spaceToggle=true
icon="嬨"
else
icon=""
fi
# Make sure to toggle spaces between interfaces for legibility echo "$icon" "$1"
spaceToggle=
space=
for interface in "${interfaces[@]}"
do
if [ ! $spaceToggle ]; then
space=""
spaceToggle=true
else
space=" "
fi
echo -n "$space"嬨 "$interface"
done

View File

@ -48,7 +48,7 @@ inherit = bar/base-laptop
monitor = ${env:MONITOR:eDP1} monitor = ${env:MONITOR:eDP1}
modules-left = bspwm modules-left = bspwm
modules-center = battery0 battery1 wlan wireguard bluetooth modules-center = battery0 battery1 wlan wg0 wg1 bluetooth
modules-right = xbacklight volume-laptop memory cpu temperature filesystem docker updates-arch-combined mail reddit github rss weather date modules-right = xbacklight volume-laptop memory cpu temperature filesystem docker updates-arch-combined mail reddit github rss weather date
tray-position = right tray-position = right
@ -392,7 +392,7 @@ type = custom/script
exec = ~/.config/polybar/bin/rsscount exec = ~/.config/polybar/bin/rsscount
click-left = setsid alacritty --class newsboat,newsboat -e /usr/bin/newsboat click-left = setsid alacritty --class newsboat,newsboat -e /usr/bin/newsboat
click-middle = setsid newsup click-middle = setsid ~/.local/bin/newsup
[module/mail] [module/mail]
type = custom/script type = custom/script
@ -420,11 +420,17 @@ tail = true
click-left = sh ~/.config/polybar/bin/system-usb-udev --mount & click-left = sh ~/.config/polybar/bin/system-usb-udev --mount &
click-right = sh ~/.config/polybar/bin/system-usb-udev --unmount & click-right = sh ~/.config/polybar/bin/system-usb-udev --unmount &
[module/wireguard] [module/wg0]
type = custom/script type = custom/script
exec = ~/.config/polybar/bin/wireguard-status exec = ~/.config/polybar/bin/wireguard-status wg0
;This doesn't work when run in the background for some reason ;This doesn't work when run in the background for some reason
click-left = ~/.local/bin/wireguard-switch click-left = ~/.local/bin/wireguard-switch wg0
[module/wg1]
type = custom/script
exec = ~/.config/polybar/bin/wireguard-status wg1
;This doesn't work when run in the background for some reason
click-left = ~/.local/bin/wireguard-switch wg1
[module/weather] [module/weather]
type = custom/script type = custom/script

View File

@ -1,18 +1,19 @@
#!/usr/bin/env sh #!/usr/bin/env bash
### ###
# Switch wireguard vpns up/down # Switch wireguard vpns up/down
### ###
STATUS="$(nmcli device status | grep -c wg0)" STATUS="$(nmcli device status | grep -c $1)"
case $STATUS in case $STATUS in
1) 1)
wg-quick down wg0 wg-quick down "$1"
notify-send.py -a wireguard --replaces-process wireguard-status -i network-vpn-offline-symbolic Wireguard "Connection down" & notify-send.py -a wireguard --replaces-process wireguard-status-"$1" -i network-vpn-offline-symbolic "Wireguard $1" "Connection down" &
;; ;;
*) *)
wg-quick up wg0 wg-quick up "$1"
notify-send.py -a wireguard --replaces-process wireguard-status -i network-vpn-symbolic Wireguard "Connection up" & notify-send.py -a wireguard --replaces-process wireguard-status-"$1" -i network-vpn-symbolic "Wireguard $1" "Connection up" &
;; ;;
esac esac