Closed smac89 closed 6 years ago
The idea of dotdrop is to have the ability to store a specific dotfile only once and deploy it with a different content on different host. To achieve this, it uses jinja2 which is a templating engine that allows to specify, during the dotfile installation with dotdrop, based on the selected profile, how (with what content) the dotfile will be installed. See the example in the README: https://github.com/deadc0de6/dotdrop#example
Therefore you need to import your zshrc
only once (on host1
for example with the import
command) and then edit it in dotdrop to insert specific jinja2 templating commands such that its content will be changed depending on which profile you use when you install it. These jinja2 commands are usually only if
statement that will define if a specific part of the file is to be written to the final file when installing for a specific profile.
For example, looking at your dotfiles, only a single zshrc
should be present and then needs to be adapted/edited such that it will generate a different content if you install it for profile host1
or profile host2
. Below is an example on how the beginning of that zshrc
file should look like in dotdrop (I'm taking zshrc_home
is for host host1
):
################################################################################
################################### ZGEN #######################################
################################################################################
source "$HOME/.zgen/zgen.zsh"
zgen load zsh-users/zsh-completions
{%@@ if profile == "host1" @@%}
# brew
export HOMEBREW_BUILD_FROM_SOURCE=1
zgen load smac89/linuxbrew
{%@@ endif @@%}
zgen load zdharma/fast-syntax-highlighting
zgen load zsh-users/zsh-autosuggestions
# nvm
export NVM_DIR="$HOME/.nvm"
{%@@ if profile == "host1" @@%}
export NVM_LAZY_LOAD=true
{%@@ endif @@%}
export NVM_AUTO_USE=true
zgen load lukechilds/zsh-nvm
...
The if
statements will only be taken when installing for profile host1
and thus those parts will be present in the final file only when installing for host1
thus allowing the same dotfile (stored in dotdrop) to be generated differently on different host. Of course more complex behavior (for loops, env variables, ...) can be achieved with jinja2, for more, see the jinja2 offical doc as well as how other people are using dotdrop: https://github.com/deadc0de6/dotdrop#people-using-dotdrop.
Hope this helps
@deadc0de6 That's pretty cool. I will make use of the templating stuff then.
Thank you!
I find myself doing the following in config.yml
So in essence, I wanted to manage the same location for my
.zshrc
, but for different hosts and by extension different configurations.When I did
dotdrop import -p host1 ~/.zshrc
, it creates a dotfile with the namezshrc
. Then when I did the same for my other host (dotdrop import -p host2 ~/.zshrc
), it will simply default to sharing that file for both hosts. This is not what I want.To accomplish what I wanted, I have created separate files for both hosts and changed the config accordingly. Am I missing a command for doing this, or do I have to do this manually each time? I feel like this should be part of the basic functionality.
I have no problem doing it manually seeing as it still works when I install the files, but I was wondering if I am missing a built-in way for doing this.
Thanks