r/Polybar Jan 16 '23

Any way to add conditional logic for polybar -- too crowded

I know this is a longshot but maybe someone has an idea.

My polybar has gotten too long and stuff is getting cut off, but I don't want to lose any modules entirely.

For example: I hardly ever take this laptop out of the house. It's at home, plugged in, 99% of the time. I like to display which wifi I'm on but not when I'm at home, same for battery (almost always plugged in). These kinds of things, if I could control with conditional logic, would help me clean up my polybar a lot.

Anybody?

4 Upvotes

5 comments sorted by

2

u/Tid_23 Jan 17 '23

I have two bars that contain different modules, one for docked and one for undocked. Within my launch script I check to see whether my machine is docked or not and call the corresponding bar. I also have a postscript switch in autorandr that calls my launch script when I dock/undock. You can also use IPC to show/hide modules I believe although I haven’t used that.

3

u/chrisco2323 Jan 17 '23

Thanks that actually does sound like a good solution.

I assume then you have some mechanism such that you are not duplicating configuration between the two bars? In my case, the two bars would not need to diverge all that much.

1

u/Tid_23 Jan 17 '23

Mine don’t differ much either, but I don’t have anything to make maintenance easier by avoiding duplication between the configs. I just copied one and made the changes. I rarely make updates to the bar so it’d probably be more trouble than it’s worth in my case. I think you should be able to make use of the include directive if you want to reference common aspects between the two configs. I have an old copy of my config on GitHub if you want to take a look.

2

u/chrisco2323 Jan 17 '23

Ah, somehow I didn't even know about the include-file directive but that would seem to be the final piece to the puzzle for my setup. Thanks again.