Running Waybar with a Custom Configuration Directory in Sway

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:

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:

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:

Make it executable:

Then reference it in your Sway config:

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:

Your display manager or TTY login will source this file, making the script discoverable when Sway starts.

Leave a Reply

This site uses Akismet to reduce spam.Learn how your comment data is processed.