Elektra
0.8.24
|
This plugin allows read/write of INI files. INI files consist of simple key value pairs of the form key = value
. Additionally keys can be categorized into different sections. Sections must be enclosed in "[]", for example "[section]". Each section is converted into a directory key (without value) and keys below the section are located below the section key. If the same section appears multiple times, the keys of all sections with the same name are merged together under the section key.
The plugin is feature rich and customizable (+1000 in status)
If you want to add an ini file to the global key database, simply use mount:
Then you can modify the contents of the ini file using set:
Find out which file you modified:
The ini plugin supports the use of comments. Comment lines start with a ';' or a '#'. Comments are put into the comment metadata of the key following the comment. This can be either a section key or a normal key. When creating new comments (e.g. via kdb setmeta
) you can prefix your comment with the comment indicator of your choice (';' or '#') which will be used when writing the comment to the file. If the comment is not prefixed with a comment indicator, the ini plugin will use the character defined by the comment
option, or default to '#'.
The ini plugin supports multiline ini values. Continuations of previous values have to start with whitespace characters.
For example consider the following ini file:
This would result in a KeySet containing two keys. One key named key1
with the value value1
and another key named key2
with the value value2\nwith continuation\nlines
.
By default this feature is enabled. The default continuation character is tab (\t
). If you want to use another character, then please specify the configuration option linecont
.
The ini plugin handles repeating keys by turning them into an elektra array when the array
config is set.
For example a ini file looking like:
will be interpreted as
The following example shows how you can store and retrieve array values using the ini
plugin.
By default the INI plugin does not support binary data. You can use the Base64 plugin to remove this limitation.
```
base64
(which provides binary
) at the end too,sudo kdb mount –with-recommends config.ini user/tests/ini ini base64
printf 'nothing = "@BASE64"
' > kdb file user/tests/ini
kdb cp system/elektra/modules/ini/exports/get user/tests/ini/binary
kdb set user/tests/ini/text 'Na na na na na na na na na na na na na na na na Batman!'
kdb get user/tests/ini/nothing #>
kdb get user/tests/ini/binary
kdb get user/tests/ini/text #> Na na na na na na na na na na na na na na na na Batman!
kdb rm -r user/tests/ini sudo kdb umount user/tests/ini
sudo kdb mount config.ini user/tests/ini ini
kdb set user/tests/ini/brand new kdb setmeta user/tests/ini/brand description "The Devil And God Are Raging Inside Me" kdb setmeta user/tests/ini/brand rationale "Because I Love It"
kdb file /tests/ini | xargs cat #> # description = The Devil And God Are Raging Inside Me #> # rationale = Because I Love It #> brand = new
kdb lsmeta user/tests/ini/brand | grep –invert-match 'internal'
kdb getmeta user/tests/ini/brand description #> The Devil And God Are Raging Inside Me kdb getmeta user/tests/ini/brand rationale #> Because I Love It
comment
!kdb setmeta user/tests/ini/brand comment "Where Art Thou?" kdb getmeta user/tests/ini/brand comment
kdb rm -r user/tests/ini sudo kdb umount user/tests/ini ```
The ini plugin supports 3 different sectioning modes (via section=
):
NONE
sections wont be printed as [Section]
but as part of the key name section/key
NULL
only empty keys will be printed as [Section]
ALWAYS
sections will be created automatically. This is the default setting:By changing the option section
you can suppress the automatic creation of keys. E.g., if you use NULL
instead you only get a section if you explicitly create it:
The ini plugin supports merging duplicated section entries when the mergesections
config is set. The keys will be appended to the first occurrence of the section key.
The ini plugin preserves the order. Inserted subsections get appended to the corresponding parent section and new sections by name.
Example:
The INI plugin also supports values and keys containing delimiter characters (=
) properly.
``` sudo kdb mount test.ini user/tests/ini ini
printf '[section1]
' > kdb file user/tests/ini
printf 'hello = world
' >> kdb file user/tests/ini
kdb get user/tests/ini/section1/hello #> world
kdb set user/tests/ini/section1/x=x 'a + b = b + a' kdb get user/tests/ini/section1/x=x #> a + b = b + a
kdb rm -r user/tests/ini sudo kdb umount user/tests/ini ```