Sometimes a well-designed, purpose-built tool can replace so many kludgy solutions. This doesn’t solve the problem of reinstating the dotfiles to their original positions in a new machine.
I’ve tried everything from raw git to gnu stow to manual symlinking and everything in between. They all work when the full context of the workflow is fresh in my brain. But after a few weeks I always mess up, even though I’ve documented the process in my dotfiles repo.
I eventually settled on chezmoi, and it just works. I set it up a year ago and haven’t needed anything beyond chezmoi -v diff and chezmoi -v apply.
The post does say exactly how to do that. Just init your homedir as a repo, add a remote, and pull. Your dotfiles come right down on top of your new machine's home directory.
Git is great, but it doesn’t solve the problem of removing unused dotfiles. For that, I use a custom script that accepts a configuration file mapping each file/directory to a package on my system. Then, when I remove those packages, I’m notified to delete its dotfiles.
I’ve found this helpful for evaluating new packages without cluttering my home directory. It’s especially helpful when using many packages that don’t respect the XDG Base Directory specification; they tend to dump dotfiles directly in my home directory, so keeping it clean is important.
I use https://github.com/nycksw/ocd which is just the famous StreakyCobra suggestion plus a pre-commit hook to prevent accidentally checking in your whole homedir. There's also a big ignore-file to prevent checking in secrets. I use it daily across several systems. It's intuitive if you use Git a lot. I don't miss my old pattern of farming symlinks.
9 comments
[ 4.3 ms ] story [ 28.2 ms ] threadThe problem with this approach is that you can accidentally commit to the $HOME repository.
An approach that avoids that is to use --git-dir= attribute.
E.g. alias dotfiles="git --git-dir=$HOME/.dotfiles"
I’ve tried everything from raw git to gnu stow to manual symlinking and everything in between. They all work when the full context of the workflow is fresh in my brain. But after a few weeks I always mess up, even though I’ve documented the process in my dotfiles repo.
I eventually settled on chezmoi, and it just works. I set it up a year ago and haven’t needed anything beyond chezmoi -v diff and chezmoi -v apply.
https://news.ycombinator.com/item?id=11071754
I’ve found this helpful for evaluating new packages without cluttering my home directory. It’s especially helpful when using many packages that don’t respect the XDG Base Directory specification; they tend to dump dotfiles directly in my home directory, so keeping it clean is important.