twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

promptStringOnce only stores variables under [data] #2938

Closed dboeckenhoff closed 1 year ago

dboeckenhoff commented 1 year ago

What exactly are you trying to do?

My .chezmoi.toml.tmpl does

{{- $database := promptStringOnce . "database" "Please add the path to your keepass2 database to be used via keepassxc cli" -}}

[keepassxc]
    database = {{ $database | quote }}

However, with chezmoi init I am always prompted the database entry request. This is rather invonvenient. If this is possible, I'd say the proper way should be documented.

What have you tried so far?

The same syntax storing under [data] works. However, keepassxc requires the database entry to be under [keepassxc] (as I understand it).

Where else have you checked for solutions?

Finally

Thanks for this awesome project!

halostatue commented 1 year ago

As a workaround, you could store things twice.

{{- $database := promptStringOnce . "keepassxc-database" "Please add the path to your keepass2 database to be used via keepassxc cli" -}}

[keepassxc]
    database = {{ $database | quote }}

[data]
# This is a workaround
keepassxc-database = {{ $database | quote }}

It seems like it could be useful, at least for chezmoi init, to have .chezmoi.config.* keys available so that you could do promptStringOnce . "chezmoi.config.keepassxc.database" "DATABASE, MORTAL". I don’t know that it would be useful for normal usage.

twpayne commented 1 year ago

Thanks for the suggestion. Adding a .chezmoi.config template variable makes sense. Done in #2940.

halostatue commented 1 year ago

@dboeckenhoff I believe that once this is released, your template would be updated to

{{- $database := promptStringOnce . "chezmoi.config.keepassxc.database" "Please add the path to your keepass2 database to be used via keepassxc cli" -}}

[keepassxc]
    database = {{ $database | quote }}