yadm-dev / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
5.11k stars 175 forks source link

Same files - different locations #451

Closed grasegger closed 1 year ago

grasegger commented 1 year ago

This question is about

Describe your question

Some tools (like aerc) put their macos configs in ~/Library/Preferenes instead of the .config dir they use on linux. How would I best go about using the same config file both on darwin and linux?

When searching for this issue I found a help page by chezmoi explaining exactly what I wanna achive, but I'd rather not switch my dotfile manager ... :D https://www.chezmoi.io/user-guide/manage-machine-to-machine-differences/#handle-different-file-locations-on-different-systems-with-the-same-contents

TheLocehiliosan commented 1 year ago

@grasegger - Is using a symbolic link a possibility?

grasegger commented 1 year ago

@TheLocehiliosan But how would I make sure the tracked symlink only gets created on darwin systems?

TheLocehiliosan commented 1 year ago
  1. Choose a central place you want the file to exist. For my example, I'll use $HOME/.config/yadm/src/abc.
  2. This file should be added to your dotfiles repo.
  3. On the system where you want this file referenced by an system specific path do the following:
    • Create a "fully qualitified" symlink to the file from step 1, in the desired location.
    • ln -s "$HOME/.config/yadm/src/abc" "$HOME/Library/Preferenes/abc"
    • Move that new symlink under the .config/yadm/alt path, and name it using a template that will match the system. https://yadm.io/docs/alternates#
    • mv "$HOME/Library/Preferenes/abc" "$HOME/.config/yadm/alt/Library/Preferenes/abc##os.Darwin"
    • Add that symlink to your dotfiles repo
    • yadm add "$HOME/.config/yadm/alt/Library/Preferenes/abc##os.Darwin"
    • At this point, yadm should have created a symlink in your desired path, which points to the os.Darwin versions (which in turn points to the central version)
  4. Repeat this on the other system
    • ln -s "$HOME/.config/yadm/src/abc" "$HOME/.config/abc/abc.conf"
    • mv "$HOME/.config/abc/abc.conf" "$HOME/.config/yadm/alt/.config/abc/abc.conf##os.Linux"
    • yadm add "$HOME/.config/yadm/alt/.config/abc/abc.conf##os.Linux"
  5. The appropriate symlink will only be created on the systems that match the template you use.

I know this sounds a bit complicated, but the end result would look like this:

.config/yadm/alt/Library/Preferenes/abc##os.Darwin -> $HOME/.config/yadm/src/abc .config/yadm/alt/.config/abc/abc.conf##os.Linux -> $HOME/.config/yadm/src/abc .config/yadm/src/abc

Note: it's important to use fully qualitified symlinks on each system, because your different systems may very well have different $HOME paths.

grasegger commented 1 year ago
  1. Choose a central place you want the file to exist. For my example, I'll use $HOME/.config/yadm/src/abc.
  2. This file should be added to your dotfiles repo.
  3. On the system where you want this file referenced by an system specific path do the following:
    • Create a "fully qualitified" symlink to the file from step 1, in the desired location.
    • ln -s "$HOME/.config/yadm/src/abc" "$HOME/Library/Preferenes/abc"
    • Move that new symlink under the .config/yadm/alt path, and name it using a template that will match the system. https://yadm.io/docs/alternates#
    • mv "$HOME/Library/Preferenes/abc" "$HOME/.config/yadm/alt/Library/Preferenes/abc##os.Darwin"
    • Add that symlink to your dotfiles repo
    • yadm add "$HOME/.config/yadm/alt/Library/Preferenes/abc##os.Darwin"
    • At this point, yadm should have created a symlink in your desired path, which points to the os.Darwin versions (which in turn points to the central version)
  4. Repeat this on the other system
    • ln -s "$HOME/.config/yadm/src/abc" "$HOME/.config/abc/abc.conf"
    • mv "$HOME/.config/abc/abc.conf" "$HOME/.config/yadm/alt/.config/abc/abc.conf##os.Linux"
    • yadm add "$HOME/.config/yadm/alt/.config/abc/abc.conf##os.Linux"
  5. The appropriate symlink will only be created on the systems that match the template you use.

I know this sounds a bit complicated, but the end result would look like this:

.config/yadm/alt/Library/Preferenes/abc##os.Darwin -> $HOME/.config/yadm/src/abc .config/yadm/alt/.config/abc/abc.conf##os.Linux -> $HOME/.config/yadm/src/abc .config/yadm/src/abc

Note: it's important to use fully qualitified symlinks on each system, because your different systems may very well have different $HOME paths.

This is brilliant, I kinda forgot about tracking a symlink with git and wouldn't have thought that yadm just treats them like files.