andsens / homeshick

git dotfiles synchronizer written in bash
MIT License
2.11k stars 145 forks source link

Ability to track a whole directory #220

Closed nyurik closed 11 months ago

nyurik commented 11 months ago

the track command seem to only support individual files. Is there a good way to track a whole directory?

andsens commented 11 months ago

Yup. If you check out the linking table you'll see that symlinks are symlinked. So if you add a directory to your repo outside of home/ and symlink to that from inside home/ homeshick will link to that symlink in your actual $HOME, meaning you have an entire directory in your castle that is tracked and also accessible from a place of your choosing in $HOME.

nyurik commented 11 months ago

@andsens if i understood you correctly, homeshick will handle symlinked directories properly, but it does not offer any tools to create such symlinks from existing directories? E.g. if nothing is tracked, there is no homeshick command to add it, but i can do it myself with some hand-crafted ln -s ... command?

andsens commented 11 months ago

@nyurik that is correct. So e.g. if you dir is /home/yuri/.config/myapp:

$ homeshick cd dotfiles
$ mkdir config home/.config
$ mv ~/.config/myapp config/myapp
$ ln -s ../../config/myapp home/.config/myapp
$ git add .config/myapp home/.config/myapp
$ git commit -m 'Tracking all of .config/myapp now'
$ homeshick link dotfiles

(The git add & git commit are important, homeshick only links tracked files)

nyurik commented 11 months ago

@andsens thanks for the great in-depth reply! Do you think it would make sense to add dir handling to the track command (or a new track-dir command?)

andsens commented 11 months ago

@nyurik I do not. There are quite a few other scenarios where playing around with symlinks makes sense, and the one where you track a directory is just one of them.

By the way: I gave you the wrong link, here is the proper explanation of how it works.

The power of the linking table lies in its versatility. Take for example the "dir is symlink in $HOME and actual directory in homeshick" field in the linking table (bottom left), you can get homeshick to track files outside of $HOME (e.g. make a link to /etc/someapp from /home/yuri/.config/someapp and then add something in .../dotfiles/home/.config/someapp, homeshick will traverse into that folder and place a link there).
So the track-dir would just be one edge-case out of many, the help menu would explode if we added all scenarios :-)

read more here