Replies: 4 comments 2 replies
-
What I’m going to suggest here is useful only if the As of the moment, storing the result is your best bet. I’d suggest a #!/bin/bash
cat > /tmp/sortedData <<EOF
{{ .dataToSort | sortAlpha | reverse | toJson }}
EOF Then you should be able do At the end, you can have an |
Beta Was this translation helpful? Give feedback.
-
@twpayne @bradenhilton this might be a good idea for the #2673 templating. Something like |
Beta Was this translation helpful? Give feedback.
-
You can reuse template code by using There is no way in chezmoi to store the result of a template execution and re-use it elsewhere. Such a thing is both a very bad idea and impossible to implement. It is impossible to implement because chezmoi's templates are neither hermetic nor idempotent so chezmoi cannot determine when the result of a template execution can be reused. Consider the small "computation" It is a very bad idea because, even it were possible to implement correctly (which would first require solving the halting problem) it would result in a large, shared, global state, with all the nightmares that that brings. Think how bad global variables are. This would be even worse. |
Beta Was this translation helpful? Give feedback.
-
Thanks both for engaging :) So basically that's option 2, reuse template code by including them. The word "compute" could be a bit misleading, but in reality I was talking about code reuse. |
Beta Was this translation helpful? Give feedback.
-
Let's say I have a small "computation" using some data stored in
chezmoi.toml.tmpl
and this is repeated over several templates.I'm curious to know if there would be ways to reuse template code like this. I thought of two possible options:
chezmoi.toml.tmpl
with the caveat that it uses data defined there, so I imagine it will not be available during evaluationFor something that small I'm fine with copying/pasting, but I'm wondering how one would solve this.
Beta Was this translation helpful? Give feedback.
All reactions