When setting upSwayas your Wayland compositor, you might want to organize yourWaybarconfiguration in a non-standard location — for example, keeping a dedicated~/.config/waybar/sway/directory to separate your Sway-specific bar configuration from others.
This seemingly simple task comes with a couple of subtle pitfalls worth knowing about.
The~Expansion Problem
The most natural approach would be to launch Waybar directly from thebarblock in your Sway config:
1 2 3 4 | bar{ swaybar_commandwaybar--config~/.config/waybar/sway/config.jsonc } |
Unfortunately, thisdoes not work. Theswaybar_commanddirective does not perform shell expansions, so~is passed literally to the command instead of being expanded to your home directory. Waybar will fail to find the configuration file.
A workaround is to launch Waybar viaexecinstead:
1 2 3 | # This works, but... execwaybar--config~/.config/waybar/sway/config.jsonc |
However, this approach has its own drawback: Waybar launched viaexecis no longer managed by Sway’sbarsubsystem. This means that Sway bar commands — such asswaymsg bar hidden_state toggleto show/hide the bar —will not work.
The Solution: A Wrapper Script
The cleanest solution is to write a small wrapper script that handles the expansion and launches Waybar with the desired configuration:
1 2 3 4 | #!/bin/bash execwaybar--config~/.config/waybar/sway/config.jsonc\ --style~/.config/waybar/sway/style.css |
Make it executable:
1 2 | chmod+x~/.local/bin/sway-waybar.sh |
Then reference it in your Sway config:
1 2 3 4 | bar{ swaybar_commandsway-waybar.sh } |
Now Waybar is properly managed by Sway’s bar subsystem, and the script handles path expansion.
The PATH Problem
There is one more subtle issue: the script lives in~/.local/bin/, which maynot be inPATHwhen Sway starts. Sway is typically launched from a display manager or TTY, where the environment is minimal and does not source your shell’s configuration files (e.g.,~/.bashrcor~/.zshrc).
To ensure~/.local/binis inPATHfor Sway and all processes it spawns, add it in your login shell profile:
1 2 | exportPATH="$HOME/.local/bin:$PATH" |
Your display manager or TTY login will source this file, making the script discoverable when Sway starts.