swayblocks icon indicating copy to clipboard operation
swayblocks copied to clipboard

Allow specifying config file at runtime

Open DerVerruckteFuchs opened this issue 4 years ago • 1 comments

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.

DerVerruckteFuchs avatar May 09 '20 12:05 DerVerruckteFuchs

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)

rei2hu avatar May 10 '20 16:05 rei2hu