#toggle #state #click #waybar #styling #config #safety #themes #true #wg-toggle

app wg-toggle

Toggle Wireguard connection state

1 stable release

Uses new Rust 2024

new 1.0.0 May 15, 2025

#3 in #click

MIT license

8KB
99 lines

๐Ÿ” Waybar WireGuard VPN Toggle (Rust)

A lightweight, fast, and minimal Rust-based utility for managing WireGuard VPNs via NetworkManager (nmcli). Built for integration into Waybar as a custom module, it allows users to:

  • Toggle VPN on/off with a click
  • Rotate between configured VPNs via scroll or right-click
  • Display current VPN status in Waybar
  • Output proper JSON for color and icon styling

๐Ÿ“ฆ Features

  • ๐Ÿš€ Written in Rust for speed and safety
  • ๐Ÿง  Remembers current VPN between reboots (/tmp/wg-current)
  • ๐Ÿ–ฑ๏ธ Scroll or right-click to cycle through VPN configs
  • ๐ŸŽจ Emits Waybar-compatible JSON for visual theming

๐Ÿ›  Dependencies

  • NetworkManager
  • WireGuard support via nmcli (import .conf files with nmcli connection import)
  • waybar with custom module support

๐Ÿ”ง Installation

1. Clone and build

git clone https://github.com/yourusername/wg-waybar-toggle
cd wg-waybar-toggle
cargo build --release

2. Move binary to somehwere in your $PATH:

cp target/release/wg-toggle ~/.local/vin/

๐Ÿ–ผ๏ธ Waybar Integration

Example module config:

"custom/wg": {
  "exec": "~/.local/bin/wg-toggle --status",
  "return-type": "json",
  "interval": 10,
  "on-click": "~/.local/bin/wg-toggle",
  "on-click-right": "~/.local/bin/wg-toggle next",
  "on-scroll-up": "~/.local/bin/wg-toggle previous",
  "on-scroll-down": "~/.local/bin/wg-toggle next",
  "tooltip": true
}

Example CSS:

#custom-wg.active {
  background-color: #a6e3a1;
  color: #1e1e2e;
}

#custom-wg.inactive {
  background-color: #45475a;
  color: #cdd6f4;
}

โš™๏ธ Behavior

Action Result
Left Click Toggle current VPN on/off
Scroll Up Switch to previous VPN config
Scroll Down Switch to next VPN config
Right Click Switch to next VPN config
Auto-refresh Show current VPN status

๐Ÿ“ VPN Configuration

Use nmcli to import .conf files:

nmcli connection import type wireguard file wg-home.conf
nmcli connection import type wireguard file wg-work.conf

Names must be valid Linux interface names (<=15 characters, no spaces).

๐Ÿงช Debugging

To test the output:

~/.local/bin/wg-toggle --status
~/.local/bin/wg-toggle
~/.local/bin/wg-toggle next

๐Ÿชช License

MIT

๐Ÿค Contributing

Pull requests and suggestions are very welcome!
If you'd like to improve the script, support more VPN managers, or enhance the Waybar integration, feel free to open an issue or PR.

Please ensure any code contributions:

  • Are formatted with rustfmt
  • Include basic error handling
  • Preserve existing CLI behavior

No runtime deps