deadc0de6 / dotdrop

Save your dotfiles once, deploy them everywhere
https://dotdrop.readthedocs.io
GNU General Public License v3.0
1.79k stars 105 forks source link

[help] Using variables in config section #346

Closed RayZ0rr closed 2 years ago

RayZ0rr commented 2 years ago

What I am trying to achieve I have an environment variable in .bashrc like this:

export DOTDIR="/some/path/to/dotfiles"

I want to use it with my dotdrop config like this:

config:
  dotpath: "{{@@ env['DOTDIR'] @@}}/dotfiles"

But this environmental variable doesn't get evaluated,

Then I changed it like this:

variables:
  myDots: "gFolder"
config:
  dotpath: "{{@@ myDots @@}}/dotfiles"

But I get the error:

[ERR] config error: undefined variable: 'myDots' is undefined

Is it possible to use variables here?

deadc0de6 commented 2 years ago

No, unfortunately it is not possible to use variables in dotpath. A list of elements of the config where variables can be used is listed here. Can you tell me more on your use-case/need, maybe we can work something out if that's something you need.

I'm however surprised by the second error you get since I cannot reproduce it. Whenever I use a variable in dotpath then simply the variable is not expanded and file is not found. I'm guessing you have an issue in a different part of your config file.

RayZ0rr commented 2 years ago

Yes, the second error was a problem with my config.

For, the first one I just thought I can keep my config file anywhere and not on the same directory as config.yaml exists. I was initially planning to give it like this: dotpath: "{{@@ env['HOME'] @@}}/gitfolder" but this is not really a big problem. Actually this is not even a inconvenience so I rather not turn this into a feature. I am very happy with how dotdrop works and wouldn't want to risk it breaking from minor features like this.

deadc0de6 commented 2 years ago

@RayZ0rr I added support for templating the dotpath entry. The following would work:

config:
  dotpath: "{{@@ env['SOME_VAR'] @@}}"

or

config:
  dotpath: "{{@@ val @@}}"
variables:
  val: "/tmp/xyz"

This will be part of the next release

deadc0de6 commented 2 years ago

@RayZ0rr this is now available in version v1.9.0