Closed bradenhilton closed 1 year ago
The .tmpl
suffix means that the file is interpreted as a template before being executed.
In the case of modify templates it makes the modify template a template whose result is a template, and the result template is the one with a .chezmoi.stdin
variable set. This is almost certainly not what you want.
Basically, don't add .tmpl
suffixes to your modify templates because they are already templates. If you want syntax highlighting then you can use a VIM modeline.
Understandable, though this does mean there is no way to know if a modify_
file is a script or modify template at a glance.
We can close if this is invalid, I'll leave it up to you.
Yeah, I agree that the behavior is initially surprising, but I think it is consistent.
I suspect that @bradenhilton won’t be the last person to run into this, so we should probably add a paragraph or two about this to the documentation about the chezmoi:modify-template
directive.
Indeed, fair point. I've pushed a warning to the docs in 55b72c657874a8f24911449b11186038cf2097f4. I've not added an explanation as I couldn't come up with a short, easy-to-understand explanation.
Describe the bug
Attempting to use
.chezmoi.stdin
in a modify template with a.tmpl
suffix gives a... at <.chezmoi.stdin>: map has no entry for key "stdin"
error.To reproduce
test
:modify_test.tmpl
:Expected behavior
The
.tmpl
suffix, even if redundant, should not give an error or reduce functionality.Output of command with the
--verbose
flagOutput of
chezmoi doctor
Additional context
The directive can enable templating without the suffix, which is not immediately obvious:
modify_<name>{.<ext>}
modify_<name>{.<ext>}.tmpl
modify_<name>{.<ext>}
withmodify-template
directivemodify_<name>{.<ext>}.tmpl
withmodify-template
directive.chezmoi.stdin
no longer works