twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.85k stars 477 forks source link

Apply only a predefined list of dotfiles rather than all of them #958

Closed reputet closed 3 years ago

reputet commented 3 years ago

Hi, thanks for developing and maintaining such an outstanding tool!

Is your feature request related to a problem? Please describe.

I'm trying to apply only a subset of managed dotfiles, not all of them. And I'm looking for an option to define these sets beforehand so that they can be used later while applying with a single command.

Let' say there is a following list of dotfiles:

And I have two machines: a home PC and a workstation.

My goal is to apply only a few of these files on a particular machine. E.g. I want .bashrc, .htoprc and .vimrc to be applied on workstation and only .vimrc, .vlc/vlcrc and .zshrc on my home PC.

Describe the solution you'd like

From my perspective, it might look like

$ chezmoi apply --profile workstation

to add the abovementioned files (.bashrc, .htoprc and .vimrc) to the home directory on the workstation.

Describe alternatives you've considered

I believe here is an example of how a similar feature is implemented in another dotfiles manager as a concept of profiles. It keeps a config.yaml file with defined profiles:

profiles:
  home:
    dotfiles:
    - f_vimrc
    - f_xinitrc
    - d_polybar
  office:
    dotfiles:
    - f_xinitrc
    - d_polybar

And you're allowed to choose which profile you want to deploy the files from:

$ dotdrop install --profile=office
twpayne commented 3 years ago

Short (wrong) answer: chezmoi apply takes a list of targets, so you can run

chezmoi apply ~/.bashrc ~/.htoprc ~/.vimrc

on workstation and

chezmoi apply ~/.vimrc ~/.vlc/vlcrc ~/.zshrc

on your home PC. But this isn't the right answer.

Long (correct) answer: with chezmoi the idea is that you can run chezmoi apply on different machines and get the right set of dotfiles for the machine you're running on. Instead of profiles, chezmoi uses templates and files like .chezmoiignore to ensure that the right set of dotfiles get installed on each machine.

In the specific case you give, I would recommend creating a template variable called workstation (for example) that you set in your config file and then use in .chezmoiignore and in your dotfile templates. #957 is relevant.

twpayne commented 3 years ago

Thank you very much for the very clear description of the problem - much appreciated!

twpayne commented 3 years ago

FYI my personal .chezmoiignore is here.

reputet commented 3 years ago

Tom, thanks so much for your instant and detailed reply!

Template approach is not as straightforward as the configuration one in the example I gave, but I got the idea looking at your .chezmoiignore. It's clear now 👍