| 1 |
# Template variables |
| 2 |
|
| 3 |
## Available variables |
| 4 |
|
| 5 |
The following variables are available in templates: |
| 6 |
|
| 7 |
* `{{@@ profile @@}}` contains the profile provided to dotdrop. |
| 8 |
* `{{@@ env['MY_VAR'] @@}}` contains environment variables (see [Environment variables](#environment-variables)). |
| 9 |
* `{{@@ header() @@}}` contains the dotdrop header (see [Dotdrop header](templating.md#dotdrop-header)). |
| 10 |
* `{{@@ _dotdrop_dotpath @@}}` contains the [dotpath](../config/config-config.md) absolute path. |
| 11 |
* `{{@@ _dotdrop_cfgpath @@}}` contains the [config file](../config/config-file.md) absolute path. |
| 12 |
* `{{@@ _dotdrop_workdir @@}}` contains the [workdir](../config/config-config.md) absolute path. |
| 13 |
* All variables defined [in the config](../config/config-file.md#variables) |
| 14 |
* Dotfile specific variables (see [Dotfile variables](#dotfile-variables)) |
| 15 |
|
| 16 |
## Enriched variables |
| 17 |
|
| 18 |
The below variables are added to the available variables within templates. If the variable |
| 19 |
is already set by the user (through the config file for example) it will not be overwritten. |
| 20 |
|
| 21 |
* `{{@@ os @@}}` will contain the OS name as provided by <https://docs.python.org/3/library/platform.html#platform.system> |
| 22 |
* `{{@@ release @@}}` will contain the OS release version as provided by <https://docs.python.org/3/library/platform.html#platform.release> |
| 23 |
* `{{@@ distro_id @@}}` will contain the distribution ID as provided by <https://distro.readthedocs.io/en/latest/#distro.id> |
| 24 |
* `{{@@ distro_version @@}}` will contain the distribution version as provided by <https://distro.readthedocs.io/en/latest/#distro.version> |
| 25 |
* `{{@@ distro_like @@}}` will contain a space-separated list of distro IDs that are closely related to the current OS distro as provided by <https://distro.readthedocs.io/en/latest/#distro.like> |
| 26 |
|
| 27 |
## Dotfile variables |
| 28 |
|
| 29 |
When a dotfile is handled by dotdrop, the following variables are also available for templating: |
| 30 |
|
| 31 |
* `{{@@ _dotfile_abs_src @@}}` contains the processed dotfile absolute source path. |
| 32 |
* `{{@@ _dotfile_abs_dst @@}}` contains the processed dotfile absolute destination path. |
| 33 |
* `{{@@ _dotfile_key @@}}` contains the processed dotfile key. |
| 34 |
* `{{@@ _dotfile_link @@}}` contains the processed dotfile `link` string value. |
| 35 |
|
| 36 |
In addition to the above, the following variables are set in each file processed by dotdrop: |
| 37 |
|
| 38 |
* `{{@@ _dotfile_sub_abs_src @@}}` contains the absolute source path of each file when handled by dotdrop. |
| 39 |
* `{{@@ _dotfile_sub_abs_dst @@}}` contains the absolute destination path of each file when handled by dotdrop. |
| 40 |
|
| 41 |
For example, a directory dotfile (like `~/.ssh`) would process several files |
| 42 |
(`~/.ssh/config` and `~/.ssh/authorized_keys`, for example). In `~/.ssh/config`: |
| 43 |
|
| 44 |
* `_dotfile_abs_dst` would be `/home/user/.ssh` |
| 45 |
* `_dotfile_sub_abs_dst` would be `/home/user/.ssh/config` |
| 46 |
|
| 47 |
## Environment variables |
| 48 |
|
| 49 |
It's possible to access environment variables inside the templates: |
| 50 |
``` |
| 51 |
{{@@ env['MY_VAR'] @@}} |
| 52 |
``` |
| 53 |
|
| 54 |
This allows for storing host-specific properties and/or secrets in environment variables. |
| 55 |
It is recommended to use `variables` (see [config variables](../config/config-file.md#variables)) |
| 56 |
instead of environment variables unless these contain sensitive information that |
| 57 |
shouldn't be versioned in Git (see [handle secrets doc](../howto/sensitive-dotfiles.md)). |
| 58 |
|
| 59 |
## Variables dictionary |
| 60 |
|
| 61 |
All variables are also available through the dictionary `_vars` |
| 62 |
``` |
| 63 |
{%@@ for key in _vars @@%} |
| 64 |
key:{{@@ key @@}} - value:{{@@ _vars[key] @@}} |
| 65 |
{%@@ endfor @@%} |
| 66 |
``` |