1 stable release
Uses new Rust 2024
new 1.0.0 | May 15, 2025 |
---|
#3 in #click
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 withnmcli connection import
) waybar
withcustom
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