Add polybar module for showing wireguard status
This commit is contained in:
parent
ded39cc1b7
commit
364cc7edcd
|
@ -43,7 +43,7 @@ wm-restack = bspwm
|
||||||
# clipmenu-widget: showing clipmenu service
|
# clipmenu-widget: showing clipmenu service
|
||||||
|
|
||||||
# Top modules
|
# Top modules
|
||||||
bottom-left = powermenu title bluetooth cpu memory backlight
|
bottom-left = powermenu title bluetooth wireguard cpu memory backlight
|
||||||
bottom-center = i3
|
bottom-center = i3
|
||||||
bottom-right = spotify alsa network-detail battery date
|
bottom-right = spotify alsa network-detail battery date
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ label-focused-padding = 2
|
||||||
label-focused-foreground = ${colors.nord7}
|
label-focused-foreground = ${colors.nord7}
|
||||||
label-focused-underline = ${colors.nord7}
|
label-focused-underline = ${colors.nord7}
|
||||||
|
|
||||||
label-unfocused =
|
label-unfocused =
|
||||||
|
|
||||||
label-urgent = %name%
|
label-urgent = %name%
|
||||||
label-urgent-foreground = ${colors.urgent}
|
label-urgent-foreground = ${colors.urgent}
|
||||||
|
@ -362,3 +362,9 @@ exec = ~/.config/polybar/bluetooth.sh
|
||||||
interval = 2
|
interval = 2
|
||||||
format-underline = #81a1c1
|
format-underline = #81a1c1
|
||||||
click-left = exec alacritty -e bluetoothctl
|
click-left = exec alacritty -e bluetoothctl
|
||||||
|
|
||||||
|
[module/wireguard]
|
||||||
|
type = custom/script
|
||||||
|
exec = ~/.config/polybar/polybar-wireguard
|
||||||
|
tail = false
|
||||||
|
interval = 2
|
||||||
|
|
58
.config/polybar/polybar-wireguard
Executable file
58
.config/polybar/polybar-wireguard
Executable file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Unfortunately it's not easy to directly use Polybar colour values in this
|
||||||
|
# script so I have to redefine some of my colours here. See the link below for
|
||||||
|
# more details:
|
||||||
|
# https://github.com/polybar/polybar/wiki/Formatting#format-tags-inside-polybar-config
|
||||||
|
color=#bf616a
|
||||||
|
|
||||||
|
configs_path="/PATH/TO/CONF/FILES"
|
||||||
|
connected_interface=$(networkctl | grep -P "\d+ .* wireguard routable" -o | cut -d" " -f2)
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
selected_config=$(ls $configs_path/*.conf | xargs basename -a -s .conf | dmenu)
|
||||||
|
[[ $selected_config ]] && sudo wg-quick up "$configs_path"/"$selected_config".conf
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
# Normally we should have a single connected interface but technically
|
||||||
|
# there's nothing stopping us from having multiple active intgerfaces so
|
||||||
|
# let's do this in a loop:
|
||||||
|
for connected_config in $(networkctl | grep -P "\d+ .* wireguard routable" -o | cut -d" " -f2)
|
||||||
|
do
|
||||||
|
sudo wg-quick down $configs_path/"$connected_config".conf
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle() {
|
||||||
|
if [[ $connected_interface ]]
|
||||||
|
then
|
||||||
|
disconnect
|
||||||
|
else
|
||||||
|
connect
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
if [[ $connected_interface ]]
|
||||||
|
then
|
||||||
|
echo %{u"$color"}%{+u}%{T4}%{F"$color"}%{T-}%{F-} "$connected_interface"
|
||||||
|
else
|
||||||
|
echo %{u"$color"}%{+u}%{T4}%{F"$color"}%{T-}%{F-}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
--connect)
|
||||||
|
connect
|
||||||
|
;;
|
||||||
|
--disconnect)
|
||||||
|
disconnect
|
||||||
|
;;
|
||||||
|
--toggle)
|
||||||
|
toggle
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print
|
||||||
|
;;
|
||||||
|
esac
|
Loading…
Reference in a new issue