Skip to content

Commit

Permalink
feat: Add .chezmoi.args template variable
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 29, 2021
1 parent 4c89ec8 commit 9d621f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@ chezmoi provides the following automatically-populated variables:
| Variable | Type | Value |
| -------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `.chezmoi.arch` | `string` | Architecture, e.g. `amd64`, `arm`, etc. as returned by [runtime.GOARCH](https://pkg.go.dev/runtime?tab=doc#pkg-constants). |
| `.chezmoi.args` | `[]string` | The arguments passed to the `chezmoi` command, starting with the program command. |
| `.chezmoi.fqdnHostname` | `string` | The fully-qualified domain name hostname of the machine chezmoi is running on. |
| `.chezmoi.group` | `string` | The group of the user running chezmoi. |
| `.chezmoi.homeDir` | `string` | The home directory of the user running chezmoi. |
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ func (c *Config) defaultTemplateData() map[string]interface{} {
return map[string]interface{}{
"chezmoi": map[string]interface{}{
"arch": runtime.GOARCH,
"args": os.Args,
"fqdnHostname": fqdnHostname,
"group": group,
"homeDir": c.homeDir,
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/testdata/scripts/templatevars.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ chezmoi execute-template '{{ .chezmoi.arch }}'
[ppc64] stdout ppc64
[ppc64le] stdout ppc64le

chezmoi execute-template '{{ index .chezmoi.args 1 }}'
stdout execute-template

chezmoi execute-template '{{ .chezmoi.homeDir }}'
stdout ${HOME@R}

Expand Down

0 comments on commit 9d621f7

Please sign in to comment.