Managing dotfiles using stow
Posted on January 14, 2023
One of my new year’s resolutions was to come up with a sensible way to manage my dotfiles. I evaluated a few solutions and finally settled on GNU stow.
GNU stow is a symlink manager, normally used to manage symlinks to programs
installed in /usr/local/bin. However, it can also be used to manage symlinks
to configuration files. After a bit of trial and error, I settled to the
following.
- Create a dirctory
~/Dropbox/dotfilesto store all the dotfiles. - For each package, create a subdictory
package. - Typically, the configuration files of a package are either stored in
~/.packagercor~/.config/package. Let’s usezshandkittyas canoncial examples of the two cases. - For
zsh, create a file~/Dropbox/dotfiles/zsh/dot-zshrcwhich has the contents of the desired.zshrc. - For
kitty, create a file~/Dropbox/dotfiles/dot-config/kitty/kitty.confwith the desired contents of~/.config/kitty.conf - Note that in both cases, we have replaced
.filenameor.dirnamebydot-filenameanddot-dirname.
Then run the command
stow --target $HOME --dotfiles --verbose package
for each package, which creates the appropriate symlinks. That’s it!
Well almost. There is currently a bug in stow, due to which --dotfiles
option does not work with directories. Fortunately, there is an AUR package
stow-dotfiles-git which provides a fix, at least until the fix is merged
upstream.
Update (28 Jan 2025): The bug has been resolved. So, there is no need to install stow-dotfiles-git.
It can be tedious to link each package one by one. If so, we can stow all packages at once using
find . -mindepth 1 -maxdepth 1 -type d -printf '%f ' | xargs stow --target $HOME --dotfiles --verbose
This entry was posted in OS and tagged stow, dotfile.