2

Is there a tool for managing entries of a config file? E.g: by toggling comments, or setting some keys to some values. I know, for a one-time configuration it's easy to just use sed or awk like:

awk '/regex/ {print "# " $0} !/regex/ {print}' ~/.config/foo.cfg

The problem with this is that it's limited to one kind of .cfg files and will re-invent the wheel for handling other config files like .json, .yaml, etc...

Example usage: pass specific values of often-used settings to dmenu, then let the user quickly toggle these settings on or off without having to go to a specific application, then its settings and search through the settings.

More concrete example: cfgman --toggle "youtube.com" /etc/hosts
This looks for all lines in config file matching youtube.com, then determine the comment type of that file, then toggle the comments on the matched lines. This lets the user for example create "Focus time" scripts.

Other examples:

  1. Change value of pageTemplate in ~/.config/xournalpp/settings.xml.
  2. Change value of default view in ~/.config/calcurse/conf
  3. Retrieve values of specific config properties

There are many other usage for this. It basically creates a unified interface to access all settings. The equivalent of getent but for users config.

1
  • Did my answer help @AvidSeeker?
    – Destroy666
    Jul 12 at 10:26

2 Answers 2

4

Not really. If it existed, it wouldn't be config-based, just a generic value editor of different formats.

You have apps such as:

  • yq - supports easy editing of YAML, JSON, XML, TOML and CSV
  • dasel - also supports YAML, JSON, XML, TOML and CSV, it's also a bit more popular

that support some formats but not all of them at once, includic very specific ones like hosts file.

You can also find a bunch of other tools for various syntaxes here.

0
0

To edit config files in JSON, use jq (docs).

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.