Skip to content

How to execute commands in .chezmoi.toml.tmpl with params from chezmoi vars #3191

Answered by twpayne
dgudim asked this question in Q&A
Discussion options

You must be logged in to vote

I have not run the commands, but:

{{- $git_email := promptStringOnce . "git.git_email" "Git email" -}}

This sets the $git_email local template variable.

[scriptEnv]
    GIT_EMAIL = {{ $git_email | quote }}

This sets the $GIT_EMAIL environment variable to $git_email for the next time that the script is run.

{{$signingkey := output "sh" "-c" "gpg --with-colons --locate-keys $GIT_EMAIL | grep pub | cut -d : -f 5"}}

This uses the current value of the $GIT_EMAIL environment variable. If you're running chezmoi init for the first time then this environment variable will not be set.

Fundamentally, I think the confusion here is between imperative code and declarative data. For example:

[scriptE…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@dgudim
Comment options

@twpayne
Comment options

@dgudim
Comment options

@twpayne
Comment options

Answer selected by dgudim
@dgudim
Comment options

@2-4601
Comment options

@dgudim
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants