rei2hu / swayblocks

status bar manager for i3 and sway written in elixir
17 stars 1 forks source link

Allow specifying config file at runtime #6

Open DerVerruckteFuchs opened 4 years ago

DerVerruckteFuchs commented 4 years ago

It would be nice to be able to select a different config file at runtime. Something like swayblocks -c ~/.config/swayblocks/other_config.exs would be nice. I use multiple monitors, sometimes rotated 90 degrees, and being able to have a separate config for each monitor type would be fantastic.

rei2hu commented 4 years ago

Thanks for the suggestion!

An optional runtime argument to determine the path of the config file could be a possible solution, but I'm not sure if I'll make the update in a timely fashion because I don't run a *nix system anymore.

However, there might be one (hacky) way to do it with the current config file because it is actually just some code evaluated at runtime whose return value is used as the config.

A rough example would be something like this:

case System.get_env("DISPLAY") do
  # display 1
  "localhost:0.0" ->
    [
      %{
        :name => "display 1 config",
        :time => 1000,
      }
    ]
  # display 2
  "localhost:0.1" ->
    [
      %{
        :name => "display 2 config",
        :time => 2000,
      }
    ]
  # default case in case something messes up
  _unrecognized ->
    [
      %{
        :name => "default config",
        :time => 1000,
      }
    ]
end

(also there might be a weird quirk with accessing environment variables at runtime with Elixir that actually prevents this from working? But that code is evaluated at runtime so who knows)