twpayne / chezmoi

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

Make it easier to support config files that live in different dirs on different OSes #2335

Closed garyo closed 1 year ago

garyo commented 2 years ago

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

It's pretty complicated to set up a config file that has to go in different locations on different OSes. The instructions are clear, but there are many steps and it's hard to get things set up right.

My example is espanso. Its config files (there can be several) go in AppData/Roaming/espanso/match on Windows, Library/Preferences/espanso/match on Mac, and .config/espanso/match on Linux.

My setup, following the chezmoi FAQ, is to create a file .chezmoitemplates/espanso-symbols.yml and the three config files named symbols.yml in the dirs above, containing {{- template "espanso-symbols.yml" . -}}, and a .chezmoiignore like this:

{{ if ne .chezmoi.os "darwin" }}
Library/Preferences/espanso
{{ end }}
{{ if ne .chezmoi.os "windows" }}
AppData/Roaming/espanso
{{ end }}
{{ if ne .chezmoi.os "linux" }}
.config/espanso
{{ end }}

But (newbie mistake here:) it turns out I also have to mark those files as templates -- I tried to use chezmoi chattr +template on the targets, but of course on any one system, only one of those targets exists due to the .chezmoiignore, so I have to do it one at a time on each system (git committing and pulling each time). Eventually I figured out I should have named them symbols.yml.tmpl (that's all chattr does in this case, I think -- rename them with .tmpl) and this was clear in the doc but I didn't read carefully enough.

So in all, lots of mkdir -p, and 5 files in the repo and a fair amount of head-scratching just for one config file.

Describe the solution you'd like

It would be great if chezmoi could have a config file (.chezmoilocations?) specifying alternate locations for a given config file (or template) per OS. That would get rid of all the subdirs and templates, and users could just say on Windows, this file goes there, on Mac it goes there, and on Linux it goes there. For example, given a template espanso-symbols.yml:

espanso-symbols.yml:
   windows: AppData/Roaming/espanso/match/symbols.yml
   darwin: Library/Preferences/espanso/match/symbols.yml
   linux: .config/espanso/match/symbols.yml

I do understand this might be a bit against the simple philosophy of chezmoi, but it does seem like a common use case so it might be worth addressing.

Describe alternatives you've considered

Scripts could work for this, but might be just as complicated (and harder to debug).

Additional context

Add any other context or screenshots about the feature request here.

twpayne commented 2 years ago

Thanks for the ideas! I've been thinking of a similar thing in #2273.

twpayne commented 1 year ago

As this enhancement is tracked in #2273, I'll close this issue. Let's continue the conversation in #2273.