Add wireguard module for polybar

This commit is contained in:
Thomas Dehaeze 2020-03-27 15:37:24 +01:00
parent f49e86d2c0
commit 71c0b9c7b1

View File

@ -80,7 +80,7 @@
modules-left = i3 bspwm xwindow modules-left = i3 bspwm xwindow
modules-center = modules-center =
modules-right = pulseaudio xbacklight redshift nordvpn lockscreen dunst packages unread_mail cpu battery temperature date modules-right = pulseaudio xbacklight redshift wireguard nordvpn lockscreen dunst packages unread_mail temperature battery date
wm-restack = i3 wm-restack = i3
@ -247,10 +247,9 @@
interval = 2 interval = 2
format-prefix-foreground = ${colors.fg} format-prefix-foreground = ${colors.fg}
format-underline = ${colors.bg} format-underline = ${colors.bg}
label = %{A1:$TERMINAL -e "htop" &:} ﬙ %percentage:2%% %{A} label = %{A1:$TERMINAL -e "htop" &:}﬙ %percentage:2%%%{A}
#+END_SRC #+END_SRC
* Date * Date
@ -325,23 +324,6 @@
ramp-capacity-2 =  ramp-capacity-2 = 
ramp-capacity-3 =  ramp-capacity-3 = 
ramp-capacity-4 =  ramp-capacity-4 = 
ramp-capacity-foreground = ${colors.fg}
animation-charging-0 = 
animation-charging-1 = 
animation-charging-2 = 
animation-charging-3 = 
animation-charging-4 = 
animation-charging-foreground = ${colors.fg}
animation-charging-framerate = 750
animation-discharging-0 = 
animation-discharging-1 = 
animation-discharging-2 = 
animation-discharging-3 = 
animation-discharging-4 = 
animation-discharging-foreground = ${color.fg}
animation-discharging-framerate = 750
#+END_SRC #+END_SRC
* Temperature * Temperature
@ -663,6 +645,57 @@
format-disconnected = <label-disconnected> format-disconnected = <label-disconnected>
#+end_src #+end_src
* Wireguard
#+BEGIN_SRC conf
[module/wireguard]
type = custom/script
format-underline = ${colors.bg}
click-left = ~/.config/polybar/scripts/wireguard-toggle.sh
format = <label>
exec = ~/.config/polybar/scripts/wireguard-status.sh
interval = 2
#+END_SRC
** Wireguard Connection Status
:PROPERTIES:
:header-args: :tangle ~/.config/polybar/scripts/wireguard-status.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
config="pivpn"
connection=$(sudo wg show "$config" 2>/dev/null | head -n 1 | awk '{print $NF }')
if [ "$connection" = "$config" ]; then
echo "%{F#859900} $config%{F-}"
else
echo ""
fi
#+end_src
** Toggle Wireguard Connection
:PROPERTIES:
:header-args: :tangle ~/.config/polybar/scripts/wireguard-toggle.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
config="pivpn"
connection=$(sudo wg show "$config" 2>/dev/null | head -n 1 | awk '{print $NF }')
if [ "$connection" = "$config" ]; then
sudo wg-quick down "$config" && dunstify --replace=83244 "Wireguard" "Disconnected from $config"
else
sudo wg-quick up "$config" && dunstify --replace=83244 "Wireguard" "Connected to $config"
fi
#+end_src
* Screenshot * Screenshot
#+BEGIN_SRC conf #+BEGIN_SRC conf