Skip to content

Commit

Permalink
feat: Add .chezmoi.destDir template variable
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Dec 8, 2024
1 parent ab1b31c commit fa4e390
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/chezmoi.io/docs/reference/templates/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ chezmoi provides the following automatically-populated variables:
| `.chezmoi.cacheDir` | string | The cache directory |
| `.chezmoi.config` | object | The configuration, as read from the config file |
| `.chezmoi.configFile` | string | The path to the configuration file used by chezmoi |
| `.chezmoi.destDir` | string | The destination directory |
| `.chezmoi.executable` | string | The path to the `chezmoi` executable, if available |
| `.chezmoi.fqdnHostname` | string | The fully-qualified domain name hostname of the machine chezmoi is running on |
| `.chezmoi.gid` | string | The primary group ID |
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ type templateData struct {
commandDir chezmoi.AbsPath
config map[string]any
configFile chezmoi.AbsPath
destDir chezmoi.AbsPath
executable chezmoi.AbsPath
fqdnHostname string
gid string
Expand Down Expand Up @@ -1535,6 +1536,7 @@ func (c *Config) getTemplateDataMap(cmd *cobra.Command) map[string]any {
"commandDir": templateData.commandDir.String(),
"config": templateData.config,
"configFile": templateData.configFile.String(),
"destDir": templateData.destDir,
"executable": templateData.executable.String(),
"fqdnHostname": templateData.fqdnHostname,
"gid": templateData.gid,
Expand Down Expand Up @@ -2260,6 +2262,7 @@ func (c *Config) persistentPreRunRootE(cmd *cobra.Command, args []string) error
"COMMAND": templateData.command,
"COMMAND_DIR": templateData.commandDir.String(),
"CONFIG_FILE": templateData.configFile.String(),
"DEST_DIR": templateData.destDir.String(),
"EXECUTABLE": templateData.executable.String(),
"FQDN_HOSTNAME": templateData.fqdnHostname,
"GID": templateData.gid,
Expand Down Expand Up @@ -2426,6 +2429,7 @@ func (c *Config) newTemplateData(cmd *cobra.Command) *templateData {
commandDir: c.commandDirAbsPath,
config: c.ConfigFile.toMap(),
configFile: c.getConfigFileAbsPath(),
destDir: c.DestDirAbsPath,
executable: chezmoi.NewAbsPath(executable),
fqdnHostname: fqdnHostname,
gid: gid,
Expand Down

0 comments on commit fa4e390

Please sign in to comment.