{
"$type": "site.standard.document",
"canonicalUrl": "https://rednafi.com/misc/dotfile-stewardship-for-the-indolent/",
"description": "Manage dotfiles across devices with GNU Stow. Symlink configuration files from git repo to home directory with simple, idempotent commands.",
"path": "/misc/dotfile-stewardship-for-the-indolent/",
"publishedAt": "2023-09-27T00:00:00.000Z",
"site": "at://did:plc:fgtm2c26vfcj74rfmeggbyqj/site.standard.publication/3mnl6f7ob462z",
"tags": [
"Shell",
"Unix",
"TIL",
"CLI"
],
"textContent": "I'm one of those people who will sit in front of a computer for hours, fiddling with\nalgorithms or debugging performance issues, yet won't spend 10 minutes to improve their\nworkflows. While I usually get away with this, every now and then, my inertia slithers back\nto bite me. The latest episode was me realizing how tedious it is to move config files\nacross multiple devices when I was configuring a new MacBook Air and Mac Mini at the same\ntime.\n\nI dislike customizing tools and tend to use the defaults as much as possible. However, over\nthe years, I've accumulated a few config files here and there, which were historically\nbacked up in a git repository and restored manually whenever necessary. MacOS's time machine\nmade sure that I didn't need to do it very often. So I never paid much attention to it.\n\nBut recently, I came across [GNU stow] and realized that people have been using it for years\nto manage their configs. I tried it and found that it works perfectly for what I need. It's\na nifty little tool written in perl that allows you to store all of your config files in a\ngit repository and symlink them to the targeted directories. The tool is pretty versatile\nand you can do a lot more than just dotfile management. But for this purpose, only two\ncommands will do. The workflow roughly goes like this:\n\nAll of your config files will need to live in a git repo and their directory trees will have\nto match the desired folder structure of the destination. That means, if you need to restore\na certain config file to /.config/app/.conf, then in the source repo, the file needs to\nlive in the pkg1/.config/app/.conf directory. The source's top-level directory pkg1 is\ncalled a package and can be named anything. While invoking stow, we'll refer to a particular\ndotfile by the package it lives within. Run:\n\nHere:\n\n- -v (or --verbose) makes stow run in verbose mode. When you use -v, stow will list the\n symlinks it creates or updates, making it easier to see the changes it's making.\n\n- -R (or --restow) tells stow to restow the packages. It's useful when you've already\n stowed the packages previously, and want to reapply them. The -R flag ensures that stow\n re-symlinks files, even if they already exist. This makes each run idempotent and you\n won't have to worry about polluting your workspace with straggler links.\n\n- -t <target> (or --target=<target>) specifies the target directory where stow should\n create symlinks. The default target directory is the parent of $pwd. In the above\n command, -t is used to set the home directory as the destination.\n\n- <pkg1> is the package name you want to stow.\n\nFor a more concrete example, let's say, your source repo /canvas/dot has two packages\nnamed git and zsh where the former contains .gitconfig and the latter houses .zshrc\nand .zprofile files:\n\nTo symlink both of them to the home directory, you'll need to run the following command from\nthe root of the source directory; /canvas/dot in this case:\n\nThen you can see the newly created symlinks in the home directory with this:\n\nIt prints:\n\nIf you want to remove a config file, you can unstow it with:\n\nor, manually remove the symlink with:\n\nOne neat side effect of managing configs in this manner is that, since symlinks are pointers\nto the original files living in the source repo, any changes made to the source files are\nautomatically reflected in the destination configs.\n\nHere are [my dotfiles] and a few management scripts in all their splendor!\n\n\n\n\n[gnu stow]:\n https://www.gnu.org/software/stow/\n\n[my dotfiles]:\n https://github.com/rednafi/dot",
"title": "Dotfile stewardship for the indolent"
}