deadc0de6 / dotdrop

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

[feature] define variable only works in single file level #393

Closed roachsinai closed 1 year ago

roachsinai commented 1 year ago

A clear and concise description of what you want to happen.

I'm using Vim both in WSL and Windows 11. Already using dotdrop manage dotfiles of WSL, now I'm trying using dotdrop in WSL manage dotfiles like _vimrc which locate at /mnt/c/Users/rs/_vimrc (means _vimrc is a file at Windows part).

Thanks for include provided by dotdrop, I could just write single line in file dotfiles/mnt/c/Users/rs/_vimrc:

{%@@ include 'vimrc' @@%}

Then content of Windows _vimrc will be same with WSL .vimrc.

But some times config of Windows part needed different with WSL part, for example:

-set undodir=$HOME/vimfiles/undo
+set undodir=$HOME/.vim/undo

Some config files default location of Windows part store at vimfiles rather than .vim.

So need find way to let dotdrop get set undodir=$HOME/vimfiles/undo fo _vimrc and set undodir=$HOME/.vim/undo for .vimrc.

Using templete variable like {{@@ os @@}} not works. As in wsl got Linux and dotfile _vimrc just include dotfile vimrc, content of _vimrc and .vimrc will be identical.


So if support define os variable in config.yaml like below scoop only for f__vimrc, like below

  f__vimrc:
    src: mnt/c/Users/rs/_vimrc
    dst: /mnt/c/Users/rs/_vimrc
    chmod: '777'
    os: Windows

could help a lot.

Thanks in advance!

deadc0de6 commented 1 year ago

What about defining the variables in the profile with something like this:

variables:
  vim_home_one: "$HOME/vimfiles"
  vim_home_two: "$HOME/.vim"
dotfiles:
  f_vimrc:
    src: mnt/c/Users/rs/_vimrc
    dst: /mnt/c/Users/rs/_vimrc
    chmod: '777'
profiles:
  one:
    dotfiles:
    - f_vimrc
    variables:
      vim_home: "{{@@ vim_home_one @@}}"
  two:
    dotfiles:
    - f_vimrc
    variables:
      vim_home: "{{@@ vim_home_two @@}}"

and the file content using that variable vim_home

set undodir={{@@ vim_home @@}}/undo

Note that this hasn't been tested but it gives you maybe a way to solve it.

roachsinai commented 1 year ago

Thanks for your reply. Sorry forgot about option -p of dotdrop install.