Skip to content

Commit

Permalink
Reference .chezmoidata in template data documentation
Browse files Browse the repository at this point in the history
This was introduced in #751
  • Loading branch information
cljoly committed May 25, 2021
1 parent 4191e4b commit 98d9607
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
37 changes: 37 additions & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Manage your dotfiles securely across multiple machines.
* [Scripts](#scripts)
* [Special files and directories](#special-files-and-directories)
* [`.chezmoi.<format>.tmpl`](#chezmoiformattmpl)
* [`.chezmoidata`](#chezmoidata)
* [`.chezmoiignore`](#chezmoiignore)
* [`.chezmoiremove`](#chezmoiremove)
* [`.chezmoitemplates`](#chezmoitemplates)
Expand Down Expand Up @@ -488,6 +489,42 @@ data:
email: {{ $email | quote }}
```

### `.chezmoidata`

If a file called `.chezmoidata` exists in the source state, it is interpreted
as a datasource available in most [templates](TEMPLATING.md#template-data).

#### `.chezmoidata` examples

If `.chezmoidata` contains the following (and no variable is overwritten in later stages):
```toml
editor = "nvim"
[directions]
up = "k"
down = "j"
right = "l"
left = "l"
```

Then the following template:
```
EDITOR={{ .editor }}
MOVE_UP={{ .directions.up }}
MOVE_DOWN={{ .directions.down }}
MOVE_RIGHT={{ .directions.right }}
MOVE_LEFT={{ .directions.left }}
```

Will result in:

```
EDITOR=nvim
MOVE_UP=k
MOVE_DOWN=k
MOVE_RIGHT=k
MOVE_LEFT=k
```

### `.chezmoiignore`

If a file called `.chezmoiignore` exists in the source state then it is
Expand Down
5 changes: 4 additions & 1 deletion docs/TEMPLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ chezmoi provides a variety of template variables. For a full list, run
$ chezmoi data
```

These come from a variety of sources:
These come from a variety of sources (later data overwrite earlier ones):

* Variables populated by chezmoi are in `.chezmoi`, for example `.chezmoi.os`.
* Variables created by you in the `.chezmoidata.<format>` configuration file.
The various supported formats (json, toml and yaml) are read in alphabetical
order.
* Variables created by you in the `data` section of the configuration file.

Furthermore, chezmoi provides a variety of functions to retrieve data at runtime
Expand Down

0 comments on commit 98d9607

Please sign in to comment.