$darkmode
Elektra 0.11.0
Plugin: profile

Following the elektra keyname convention application configurations are stored under /sw/org/myapp/# and /sw/org/myapp/#0/currentis the profile to be used. The profile plugin provides an easy way to switch configuration profiles.

The key /sw/org/myapp/#0/profile defines what profile should be used as current, e.g. /sw/org/myapp/#0/profile = myprofile. If a key /sw/org/myapp/#0/myprofile/key is found and no key /sw/org/myapp/#0/current/key exists an override key will be created linking /sw/org/myapp/#0/currrent/key to /sw/org/myapp/#0/myapp/key If neither /sw/org/myapp/#0/current/key nor /sw/org/myapp/#0/myprofile/key is found, but /sw/org/myapp/#0/%/key, /sw/org/myapp/#0/current/key will be linked to /sw/org/myapp/#0/%/key.

So a cascading lookup will automatically implement following preferences (next to the namespace preferences):

  1. Usage of key in current
  2. Usage of key in the profile set with profile
  3. Usage of key in the % fallback profile

Installation

See installation. The package is called libelektra5-extra.

Example

Suppose we have the configuration file profile.ini in ~/.config:

1 cat profile.ini
2 #> []
3 #> profile = myprofile
4 #>
5 #> [current]
6 #> key2 = will win
7 #>
8 #> [myprofile]
9 #> key1 = test1
10 #> key2 = test2
11 #>
12 #> [%]
13 #> key2 = failed?
14 #> key3 = test3

Then we simply mount it without the profile plugin:

1 kdb mount profile.ini /sw/org/myapp/#0 ini

But we have to make sure that the profile plugin is mounted globally:

1 kdb global-mount profile

Then we can access /sw/org/myapp/#0 in a profile-aware way:

1 kdb ls /sw
2 #> spec:/sw/org/myapp/#0/current/key1
3 #> spec:/sw/org/myapp/#0/current/key3
4 #> user:/sw/org/myapp/#0
5 #> user:/sw/org/myapp/#0/%
6 #> user:/sw/org/myapp/#0/%/key2
7 #> user:/sw/org/myapp/#0/%/key3
8 #> user:/sw/org/myapp/#0/current
9 #> user:/sw/org/myapp/#0/current/key2
10 #> user:/sw/org/myapp/#0/profile
11 #> user:/sw/org/myapp/#0/myprofile
12 #> user:/sw/org/myapp/#0/myprofile/key1
13 #> user:/sw/org/myapp/#0/myprofile/key2

As we can see with the -v option, we will fetch keys from our myprofile even though we request current:

1 kdb get -v /sw/org/myapp/#0/current/key1
2 #> got 25 keys
3 #> searching spec:/sw/org/myapp/#0/current/key1, found: spec:/sw/org/myapp/#0/current/key1, options: KDB_O_CALLBACK
4 #> The resulting keyname is user:/sw/org/myapp/#0/myprofile/key1
5 #> test1

To switch profile we simply have to set one key:

1 kdb set user:/sw/org/myapp/#0/profile newprofile

Usually, this will be done via commandline by setting proc:/sw/org/myapp/#0/profile.