-
In my
These variables I would like to use in my shell as well. So I thought of writing them from this template to a file
How can I write to a file in the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You can't, but you can make |
Beta Was this translation helpful? Give feedback.
-
The way I solved this in my envrionment, is by having a function/or script in path named: Assuming my > find ~/.config/chezmoi -name 'chezmoi.*' -print -exec cat '{}' \;
.../.config/chezmoi/chezmoi.toml
[data]
sysname = "abc"
sysgroup = "data"
sysarea = "work" Defining a PREFIX (in the code below the default is $ import-cz-data
CZ_DATA_SYSAREA="work"
CZ_DATA_SYSGROUP="data"
CZ_DATA_SYSNAME="abc" The idea is that running the following commands allows you to evaluate/source those into environment variables: . <( import-cz-data )
❯ echo $CZ_DATA_SYSAREA
work This is the code of cz-import-data() {
# Use this with eval: eval $(cz-import-data)
local UPPERCASE='|ascii_upcase'
local PREFIX="CZ_DATA_"
[[ "$1" == "promptString" ]] && unset UPPERCASE PREFIX
local RESULTS=$(
chezmoi data --format json \
| jq -r ".chezmoi.config.data" \
| jq -r "
to_entries[] |
\"$PREFIX\(.key${UPPERCASE})=\\\"\(.value)\\\"\"
"
)
if [[ "$1" == "promptString" ]] ; then
printf "$RESULTS" | tr '\n' ',' | sed 's/"//g; s/^\(.*\),$/"\1/g;'
else
echo "$RESULTS"
fi
} |
Beta Was this translation helpful? Give feedback.
You can't, but you can make
.machine
a template.