dotter icon indicating copy to clipboard operation
dotter copied to clipboard

[FEATURE] Use variables in file paths

Open tezkerek opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. I'd like to use variables in dotter's config files themselves. Something like:

[variables]
config_dir = "~/.config"

[shell.files]
"zsh/zprofile" = "~/.zprofile"
"zsh/zshrc" = "{{config_dir}}/zsh/zshrc"
"gitconfig" = "{{config_dir}}/git/config"

and then in ~/.zprofile too:

XDG_CONFIG_HOME="{{config_dir}}"

Describe the solution you'd like Maybe parse the variables first, then render a handlebars template for each path. Or is that overkill? Alternatively, maybe new values can be added to shellexpand, to be substituted like env vars ($config_dir/zsh/zshrc). ~~Might need changes upstream.~~ I think shellexpand::env_with_context could be used for this.

Describe alternatives you've considered Run dotter with variables set on the shell for shellexpand to use:

env XDG_CONFIG_HOME="~/.config" dotter deploy

tezkerek avatar Apr 01 '21 11:04 tezkerek

Currently you could just use the variable itself in the path since it's expanded (well, after running dotter once and restarting the shell I guess)

Maybe parse the variables first, then render a handlebars template for each path. Or is that overkill?

That'd be the only way of doing it. I'll test if this brings a significant slowdown, if it doesn't then I don't see a reason against this.

SuperCuber avatar Apr 01 '21 11:04 SuperCuber

I looked over shellexpand and I think that a custom context would work too, and might be more lightweight than a handlebars template. But having helpers in paths might be useful anyway.

tezkerek avatar Apr 01 '21 11:04 tezkerek

Yeah, if I'm adding access to variables might as well have full handlebars functionality, with handlebars syntax.

SuperCuber avatar Apr 01 '21 11:04 SuperCuber

This would be pretty helpful to me. I'd like to do something like:

includes = [".dotter/{{OS}}.toml"]
OR
includes = [".dotter/$OS.toml"]

This will allow me to dynamically get the correct OS files.

murkylife avatar Jun 25 '22 16:06 murkylife