~tomterl/indite

Simple ini config file manipulation
Compile against latest hare main branch.
compile against current hare master
e237817c — Tom Regner 2 months ago
report filename on write-error

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~tomterl/indite
read/write
git@git.sr.ht:~tomterl/indite

You can also use your local clone with git send-email.

Simple ini-style config file manipulation

Motivation

I want to manipulate my dotfiles setup from makefiles like this:

workmachine:
	indite -w machine.at_work=true localrc
	...

So that make workmachine will set everything up and change the local setup specific to the machine.

Tests for this setup in other places look like this if [ $(indite -r machine.at_work localrc) = "true" ];....

File format and calling conventions

The file format indite understands is quite simple:

# Header comments
# Header comments
[section1]
key=value
key=value # entry comment

[section2]
# Section comment
# Section comment
key=value # entry comment
key.subkey=value

indite allows to read values with -r keypath, and setting values with -w keypath=value.

The key path has the form `section.key[.subkey]`. The existence of subkeys is of no concern to indite, there is no im- or explicit tree structure.

Remarks

indite is written in hare.

If -r is given, indite uses stdlibs format::ini parser.

To preserve the sequence of settings and comments, if -w is given, indite reads the complete ini file into memory, without optimization considerations for now. The current implementation is straight forward. This is my first contact with hare, and the only goal for now is a working tool for my use case.

Line comments (lines starting with #) are only allowed at the beginning of the file and directly after a section-start. If you alter a file with line comments else where, they will change place and be all gathered at the allowed place.

Entry comments (anything after the first `#` after the value) will be kept on subsequent changes to the entry. To remove a comment, an empty comment has to be set (see the man page).

The ini file can be given as `-`, indite will read from stdin and write to stdout in that case (see the man page).

If the section name contains full stops, these have to be escaped, e.g. indite -r www\\.example\\.org.login credentials.ini

Contributing

Do not follow this link