Skip to content

Commit

Permalink
fix: Correct capitalization of .chezmoi.config template variables
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 21, 2023
1 parent ed0c798 commit fe6010e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ type templateData struct {
args []string
cacheDir chezmoi.AbsPath
command string
config ConfigFile
config map[string]any
configFile chezmoi.AbsPath
executable chezmoi.AbsPath
fqdnHostname string
Expand Down Expand Up @@ -2084,7 +2084,7 @@ func (c *Config) newTemplateData(cmd *cobra.Command) *templateData {
args: os.Args,
cacheDir: c.CacheDirAbsPath,
command: cmd.Name(),
config: c.ConfigFile,
config: c.ConfigFile.toMap(),
configFile: c.configFileAbsPath,
executable: chezmoi.NewAbsPath(executable),
fqdnHostname: fqdnHostname,
Expand Down Expand Up @@ -2533,6 +2533,14 @@ func newConfigFile(bds *xdg.BaseDirectorySpecification) ConfigFile {
}
}

func (f *ConfigFile) toMap() map[string]any {
var result map[string]any
if err := mapstructure.Decode(f, &result); err != nil {
panic(err)
}
return result
}

func parseCommand(command string, args []string) (string, []string, error) {
// If command is found, then return it.
if path, err := chezmoi.LookPath(command); err == nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/testdata/scripts/issue2942.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# test that .chezmoi.config variables are capitalized correctly
exec chezmoi execute-template '{{ .chezmoi.config.keepassxc.command }}'
stdout '^keepassxc-cli$'

0 comments on commit fe6010e

Please sign in to comment.