Closed julian45 closed 10 months ago
prompt*
functions aren't available outside of a chezmoi config template.
https://www.chezmoi.io/reference/templates/init-functions/
If this wasn't the case, your template would prompt you for a UUID every time the template was executed (chezmoi diff
, chezmoi apply
etc.).
I might be missing something, but I don't quite understand how that's not what I'm already trying to do here. All of the prompt*
calls are taking place within a config template, as shown in my original comment.
If I'm correctly understanding the init function reference, as well as the reference for chezmoi execute-template
, the template I described seems like it should — whether in the context of a chezmoi init
, or in a call to chezmoi execute-template
call with --init
and --promptString commitkeyuuid="[redacted]"
— evaluate $commitkeyuuid
and pass it to onepasswordDetailsFields
for evaluation.
You're using a prompt*
template function inside a template for .gitconfig
. Those functions can only be used in a template for chezmoi's own config.
See https://www.chezmoi.io/reference/special-files-and-directories/chezmoi-format-tmpl/
OK, I see now! Thank you for clarifying.
I did not quite understand from documentation that prompt*
functions were specifically limited to chezmoi's own config. In the init function reference, your link, and this FAQ answer, the words "config file" and "template" are used, and given that chezmoi is, at its core, a utility for managing configuration files of various kinds, it wasn't clear to me that the limit to .chezmoi.$FORMAT.tmpl
was present.
That, along with the prompt*
function examples' formatting looking a lot like an excerpt from a .gitconfig
file and the non-presence of filenames in those examples, led me to believe that it may have been possible to use the prompt*
functions in other templates. Sorry about that! 😅
Would it be reasonable to suggest that language could be added to some of those pages to help make the specificity clear? I would be happy to draft and make the pull request myself if so.
No need to apologize!
Would it be reasonable to suggest that language could be added to some of those pages to help make the specificity clear? I would be happy to draft and make the pull request myself if so.
Sure. Documentation improvements are always welcome and appreciated. I'll assign this issue to you (no rush)...
Please open a PR when you have a proposed changed to the documentation. In the meantime, I'll close this issue.
What exactly are you trying to do?
I have an environment in which my home and work computers have completely different 1Password accounts installed. I'm hoping to adapt my global git config file so that a given ssh key's public key can be put into the config without relying on a constant UUID in every environment. (In other words, I'd like to be able to work using my personal key on one computer, and using my work key on another, while maintaining a complete separation of 1Password accounts.) I'm not sure if this is already something that can be done with chezmoi and I'm just going about it the wrong way in this case, or if this is something new to chezmoi and thus a feature request.
What have you tried so far?
I attempted to set up my
dot_gitconfig.tmpl
as follows (simplified to focus on the question at hand):In this example, I was anticipating that upon init, I'd be prompted to input the 1Password UUID of the key they want to use, and then my answer could be evaluated within the call to
onepasswordDetailedFields
. However, when I went to test the template by runningchezmoi execute-template --init --promptString commitkeyuuid="[redacted]" < dot_gitconfig.tmpl
, I received the following error:chezmoi: template: stdin:6: undefined variable "$commitkeyuuid"
Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flagOutput of
chezmoi doctor