‹ jan0sch.de

Waybar and Wireguard status

2025-12-10

Waybar has no default support for showing Wireguard VPN connections. There are several ways to work around this issue via the waybar-custom (see man waybar-custom). So here is mine. ;-)

At first we create a helper script to more easily leverage the usage of JSON output which is then consumed by Waybar.

#!/bin/sh

CONNECTIONS=''
CONNECTIONS=$(nmcli --get-values ACTIVE,NAME,TYPE connection show 2>/dev/null | grep '^yes:.*:wireguard$' | cut -d':' -f2)

if [[ -z "${CONNECTIONS}" ]]; then
  echo "{\"text\": \"\", \"class\": \"disconnected\", \"alt\": \"disconnected\"}"
else
  echo "{\"text\": \"<big>Active connections:</big>\n${CONNECTIONS//$'\n'/\\n}\", \"class\": \"connected\", \"alt\": \"connected\"}"
fi

This script fills the variable $CONNECTIONS with the output from the nmcli command grepping only active connections of the type wireguard and then only returning a list of connection names. Afterwards we simply check if the variable is empty and return then either a JSON string containing the “disconnected” class or otherwise a JSON string containing the “connected” class and a not empty “text” attribute.

To use this in Waybar just add some lines to your configuration that look like this:

"custom/wireguard": {
  "interval": 3,
  "exec": "~/.config/waybar/wireguard-helper.sh",
  "format": "{icon}",
  "format-icons": {
      "connected": "🔒",
      "disconnected": "🔓"
  },
  "return-type": "json",
  "tooltip": true,
  "tooltip-format": "{text}"
},

It executes the script wireguard-helper.sh (be sure to get the path and name of yours right) every 3 seconds and expects JSON output from it. Using JSON we are able to use more features like choosing an icon depending on the “class” attribute and using the “text” attribute for the tooltip. The tooltip should show a list of active Wireguard connections.