3.4 KiB
Config variables
Config available variables
Multiple variables can be used within the config file to parametrize following elements of the config:
- dotfiles
srcanddstpaths (see Dynamic dotfile paths) - external path specifications
import_variablesimport_actionsimport_configs- profiles's
import
actions and transformations also support the use of variables
but those are resolved when the action/transformation is executed
(see Dynamic actions,
Dynamic transformations and Templating).
Following variables are available in the config files:
- variables defined in the config
- interpreted variables defined in the config
- profile variables defined in the config
- environment variables:
{{@@ env['MY_VAR'] @@}} - dotdrop header:
{{@@ header() @@}}(see Dotdrop header)
As well as all template methods (see Available methods)
Variables entry
Variables defined in the variables entry are made available within the config file.
Config variables are recursively evaluated what means that a config like the below
variables:
var1: "var1"
var2: "{{@@ var1 @@}} var2"
var3: "{{@@ var2 @@}} var3"
var4: "{{@@ dvar4 @@}}"
dynvariables:
dvar1: "echo dvar1"
dvar2: "{{@@ dvar1 @@}} dvar2"
dvar3: "{{@@ dvar2 @@}} dvar3"
dvar4: "echo {{@@ var3 @@}}"
will result in the following available variables:
- var1:
var1 - var2:
var1 var2 - var3:
var1 var2 var3 - var4:
echo var1 var2 var3 - dvar1:
dvar1 - dvar2:
dvar1 dvar2 - dvar3:
dvar1 dvar2 dvar3 - dvar4:
var1 var2 var3
Profile variables
Profile variables will take precedence over globally defined variables. This means that you could do something like this:
variables:
git_email: home@email.com
dotfiles:
f_gitconfig:
dst: ~/.gitconfig
src: gitconfig
profiles:
work:
dotfiles:
- f_gitconfig
variables:
git_email: work@email.com
private:
dotfiles:
- f_gitconfig
Config variables in templates
variables and dynvariables are also made available in templates
(see Template variables).
Variables in the config file
variables:
var1: some variable content
var2: some other content
Can be used in any templates like this
var1 value is: {{@@ var1 @@}}
Interpreted variables entry
It is also possible to have dynamic variables in the sense that their content will be interpreted by the shell before being substituted.
These need to be defined in the config file under the entry dynvariables.
For example:
dynvariables:
dvar1: head -1 /proc/meminfo
dvar2: "echo 'this is some test' | rev | tr ' ' ','"
dvar3: /tmp/my_shell_script.sh
user: "echo $USER"
config_file: test -f "{{@@ user_config @@}}" && echo "{{@@ user_config @@}}" || echo "{{@@ dfl_config @@}}"
variables:
user_config: "profile_{{@@ user @@}}_uid.yaml"
dfl_config: "profile_default.yaml"
They have the same properties as Variables.