Vivify icon indicating copy to clipboard operation
Vivify copied to clipboard

Viv edit config option

Open Tweekism opened this issue 3 months ago • 4 comments

Hey Jannis / Tuure,

I had an idea for a little quality-of-life feature I wanted to run by you. Details up for discussion but the basic idea would be to add a --config option or similar to viv. Eg:-

viv --config

It would look for existing configs and if found open it in your default editor. If not, create it for you, and maybe prefill out some default options. Similar to the way you edit your git config, ie:-

git config --global --edit

Rationale here is I forget things and it is a little intimidating to tell users to go hand craft a json file from scratch and put it in a valid location and currently there is no feedback if you do it wrong. With a feature like this, we could tell users to just run viv --config and change setting xxx to true or whatever.

This is something I would work on and submit as a PR. What do you guys think?

Tweekism avatar Sep 10 '25 08:09 Tweekism

Cool idea, I like it!

Creating a file with the default config is also a great idea but it's a bit more complicated than you might guess ^^ Here are my thoughts:

  1. Ultimately, we probably want to run $EDITOR <config-path>. This needs to happen in viv, not vivify-server, because vivify-server isn't connected to a terminal
  2. We don't want to add a second source of truth for the default config because then we'll have problems maintaining it, and the current single source of truth is in src/config.ts, meaning the way to access it is from vivify-server
  3. That said, editing the config with the feature of creating the default config needs to be an interplay between vivify-server and viv.

So what I'd probably do is

  • Add empty arrays for styles and scripts to the default config and export it
  • Extend the src/cli.ts with a new option --print-default-config or something that runs console.log(JSON.stringify(defaultConfig, null, 4))
  • Add the --config option to the viv script so that
    • If a config file exists, it just opens it in the editor and exits
    • If no config file exists, it runs vivify-server the way it always does at the moment, but then instead of echoing the outputs it writes them to ~/.config/vivify/config.json. Make sure to only redirects stdout there. Then open the file in the editor

jannis-baum avatar Sep 10 '25 09:09 jannis-baum

Ah and actually we'll also have to think about the same single source of truth thing for the config path(s) and precedence. So in addition to that we should also use vivify-server to resolve the config path and decide whether or not the file exists. I.e. you could adjust the ideas above to

  • always call vivify-server
  • make the new option in vivify-server print the path of the config file with highest precedence if one exists and otherwise print the default config
  • work that into viv by somehow communicating which case we're in, and acting accordingly

jannis-baum avatar Sep 10 '25 09:09 jannis-baum

make the new option in vivify-server print the path of the config file with highest precedence if one exists and otherwise print the default config

Would this perhaps be two new options?

  1. Get the config file location based on precedence and if none exists return the location it should be in based on highest precedence
  2. An option that always returns the default config (might also be useful for a future "reset config" option)

Tweekism avatar Sep 10 '25 09:09 Tweekism

Yes, could be two options but then you'd have to call vivify-server twice and for that we'd have to also change how the server is started because we don't want to go through the whole STARTUP COMPLETED thing and all that twice. Totally possible though, then I'd say we no longer start the server when options like version, --get-default-config or --get-config-path are called and instead just print the answer and quit. That way you could just do something like default_config="$(vivify-server --get-default-config)" in the shell script.

jannis-baum avatar Sep 10 '25 09:09 jannis-baum