twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

Digging into .chezmoi.config does not work in templates #2942

Closed halostatue closed 1 year ago

halostatue commented 1 year ago

Describe the bug

2940 introduced .chezmoi.config for use in templates, but trying to request the data results in a template execution error.

To reproduce

$ chezmoi execute-template '{{ .chezmoi.config.keepassxc.command  }}' 
chezmoi: template: arg1:1:11: executing "arg1" at <.chezmoi.config.keepassxc.command>: can't evaluate field keepassxc in type interface {}

Expected behavior

$ chezmoi execute-template '{{ .chezmoi.config.keepassxc.command  }}'
keepassxc-cli

Additional context

This can be worked around by piping through JSON:

$ chezmoi execute-template '{{ (.chezmoi.config | toJson | fromJson).keepassxc.command  }}'
keepassxc-cli

It is probably sufficient to use a JSON-serialized copy of the read config rather than storing the read config itself.

twpayne commented 1 year ago

Doh! Good spot. I forgot to rename the fields. Using uppercase names (as they appear in the ConfigFile struct definition works (e.g. chezmoi execute-template '{{ .chezmoi.config.Keepassxc.Command }}') but the case is wrong. Thanks for testing and fix coming up.

twpayne commented 1 year ago

Fixed with #2943 and tagged v2.33.3.