Previewing multi-platform template results on a single platform (with limitations) #4389
bradenhilton
started this conversation in
Show and tell
Replies: 2 comments 4 replies
-
I understand the template and what it does, didn't fully understand what you were trying to solve though. |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can also use environment variables and the In your template (say
And then override OS by running: $ TEST_OS=windows chezmoi cat .file |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been brainstorming ways of previewing templates whose results differ based on the current platform (OS/arch etc.).
The best I've come up with so far, which I'm somewhat disappointed I didn't think of earlier, is to use top-level template variables in place of the
.chezmoi.*
values:To preview the template result for a given platform, simply change the values of the top-level variables and execute the template with
execute-template
.In the absence of a better editor solution (extension, plugin etc.), you can use
execute-template
to output the template result to a temporary file. If your editor supports multiple buffers/panes, you can put this side-by-side with the template and re-run theexecute-template
command when the template is saved for almost real-time previewing.A major limitation of this approach is it doesn't work well in templates that use OS-specific commands/tools in
output
, or OS-specific chezmoi data like.chezmoi.osRelease
or.chezmoi.windowsVersion
. There are some workarounds but none of them are particularly elegant.One such workaround would be to wrap these calls in a condition, e.g.:
When you are happy with your template, you can simply change the top-level template variable values appropriately, e.g.:
Beta Was this translation helpful? Give feedback.
All reactions