File: template-variables.md

package info (click to toggle)
dotdrop 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: sh: 13,401; python: 8,186; makefile: 3
file content (66 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Template variables

## Available variables

The following variables are available in templates:

* `{{@@ profile @@}}` contains the profile provided to dotdrop.
* `{{@@ env['MY_VAR'] @@}}` contains environment variables (see [Environment variables](#environment-variables)).
* `{{@@ header() @@}}` contains the dotdrop header (see [Dotdrop header](templating.md#dotdrop-header)).
* `{{@@ _dotdrop_dotpath @@}}` contains the [dotpath](../config/config-config.md) absolute path.
* `{{@@ _dotdrop_cfgpath @@}}` contains the [config file](../config/config-file.md) absolute path.
* `{{@@ _dotdrop_workdir @@}}` contains the [workdir](../config/config-config.md) absolute path.
* All variables defined [in the config](../config/config-file.md#variables)
* Dotfile specific variables (see [Dotfile variables](#dotfile-variables))

## Enriched variables

The below variables are added to the available variables within templates. If the variable
is already set by the user (through the config file for example) it will not be overwritten.

* `{{@@ os @@}}` will contain the OS name as provided by <https://docs.python.org/3/library/platform.html#platform.system>
* `{{@@ release @@}}` will contain the OS release version as provided by <https://docs.python.org/3/library/platform.html#platform.release>
* `{{@@ distro_id @@}}` will contain the distribution ID as provided by <https://distro.readthedocs.io/en/latest/#distro.id>
* `{{@@ distro_version @@}}` will contain the distribution version as provided by <https://distro.readthedocs.io/en/latest/#distro.version>
* `{{@@ 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>

## Dotfile variables

When a dotfile is handled by dotdrop, the following variables are also available for templating:

* `{{@@ _dotfile_abs_src @@}}` contains the processed dotfile absolute source path.
* `{{@@ _dotfile_abs_dst @@}}` contains the processed dotfile absolute destination path.
* `{{@@ _dotfile_key @@}}` contains the processed dotfile key.
* `{{@@ _dotfile_link @@}}` contains the processed dotfile `link` string value.

In addition to the above, the following variables are set in each file processed by dotdrop:

* `{{@@ _dotfile_sub_abs_src @@}}` contains the absolute source path of each file when handled by dotdrop.
* `{{@@ _dotfile_sub_abs_dst @@}}` contains the absolute destination path of each file when handled by dotdrop.

For example, a directory dotfile (like `~/.ssh`) would process several files
(`~/.ssh/config` and `~/.ssh/authorized_keys`, for example). In `~/.ssh/config`:

* `_dotfile_abs_dst` would be `/home/user/.ssh`
* `_dotfile_sub_abs_dst` would be `/home/user/.ssh/config`

## Environment variables

It's possible to access environment variables inside the templates:
```
{{@@ env['MY_VAR'] @@}}
```

This allows for storing host-specific properties and/or secrets in environment variables.
It is recommended to use `variables` (see [config variables](../config/config-file.md#variables))
instead of environment variables unless these contain sensitive information that
shouldn't be versioned in Git (see [handle secrets doc](../howto/sensitive-dotfiles.md)).

## Variables dictionary

All variables are also available through the dictionary `_vars`
```
{%@@ for key in _vars @@%}
key:{{@@ key @@}} - value:{{@@ _vars[key] @@}}
{%@@ endfor @@%}
```