Examples of modifying part of a file with chezmoi #1746
-
I have an I'll have to say chezmoi is one of the most exhaustively documented tools I've used, so much so that it's overwhelming at times to find the info :-) Might open a discussion sometime to look at Algolia full text integration for website since with so much info some better matching might help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If the If I understand your usecase correctly, you want to ensure that Something like the following should work in #!/bin/bash
# copy the data to modify to a temporary file
tmpfile=$(mktemp)
trap "rm -f ${tmpfile}" EXIT
cat > "${tmpfile}"
# write the data to stdout
cat "${tmpfile}"
# add any missing environment variables
if [ ! grep -q ^KEY= "${tmpfile}" ]; then
echo KEY=VALUE
fi |
Beta Was this translation helpful? Give feedback.
-
I think this is the correct syntax: if ! grep -q ^KEY= "${tmpfile}"; then |
Beta Was this translation helpful? Give feedback.
modify_
scripts can be anything that can be executed, including a bash script, a Python script, or even a compiled binary if you are so inclined.If the
modify_
script has a.tmpl
extension then chezmoi will interpret it as a template before executing the result.If I understand your usecase correctly, you want to ensure that
.envrc
contains certain non-sensitive values. As these are non-sensitive, they can be included in plaintext in themodify_
script itself so you do not need to use a template to extract secrets from a password manager.Something like the following should work in
modify_dot_envrc
. Warning: I haven't tested this.