Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
halostatue opened this issue Apr 21, 2023 · 2 comments
Closed

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

halostatue opened this issue Apr 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@halostatue
Copy link
Collaborator

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 twpayne added the bug Something isn't working label Apr 21, 2023
@twpayne
Copy link
Owner

twpayne commented Apr 21, 2023

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
Copy link
Owner

twpayne commented Apr 21, 2023

Fixed with #2943 and tagged v2.33.3.

@twpayne twpayne closed this as completed Apr 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants