Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Use variables in file paths #61

Open
tezkerek opened this issue Apr 1, 2021 · 5 comments · May be fixed by #190
Open

[FEATURE] Use variables in file paths #61

tezkerek opened this issue Apr 1, 2021 · 5 comments · May be fixed by #190

Comments

@tezkerek
Copy link

tezkerek commented Apr 1, 2021

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
@SuperCuber
Copy link
Owner

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.

@tezkerek
Copy link
Author

tezkerek commented Apr 1, 2021

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.

@SuperCuber
Copy link
Owner

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

@murkylife
Copy link

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.

@yuckyh
Copy link

yuckyh commented Jul 14, 2024

Wouldn't a better solution be to have per package settings like this?

In

.dotfiles/
-zsh/
--zshrc
--zprofile
--aliases.zsh

Out

~/
-.config/
--zsh/
---.zshrc
---aliases.zsh
-.zprofile
[zsh.settings]
source_dir = "zsh"
target_dir = "~/.config/zsh" 

# Overrides
[zsh.files]
zshrc=".zshrc"

[zsh.files.zprofile]
path="exact"
target="~/.zprofile"

There should be no need for scripts and variables for paths this way. It also simplifies the configuration needed.

@balthild balthild linked a pull request Nov 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants