Stow is a fantastic tool for managing dotfiles on macOS (and other Unix-like systems). It brings a level of elegance and organization to the often-messy world of configuration files. Let’s delve into how you can harness the power of GNU Stow on your Mac.
At its core, Stow is a symbolic link farm manager. Instead of directly placing your configuration files (dotfiles) in your home directory (~), you organize them into separate directories within a central repository (often a dotfiles directory in your home directory or a version-controlled repository). Stow then creates symbolic links from these organized directories to their expected locations in your home directory.
This approach offers several benefits:
The most convenient way to install Stow on macOS is again through Homebrew. Open your Terminal and run:
brew install stow
This command will download and install Stow and any dependencies it might need. You can verify the installation by checking the installed version:
stow --version
The first step in using Stow is to create a central repository to house your configuration files. A common convention is to create a dotfiles directory in your home directory:
mkdir ~/dotfiles
cd ~/dotfiles
Within this dotfiles directory, you’ll create subdirectories for each application or configuration area you want to manage. For example, you might have directories like bash, zsh, tmux, vim, git, etc. Inside these subdirectories, you’ll place the actual configuration files as if they were directly in your home directory.
Here’s a basic example of how your ~/dotfiles structure might look:
~/dotfiles/
├── bash/
│ └── .bashrc
│ └── .bash_profile
├── git/
│ └── .gitconfig
│ └── .gitignore_global
├── tmux/
│ └── .tmux.conf
└── vim/
└── .vimrc
└── autoload/
└── pathogen.vim
Notice that the configuration files within these subdirectories retain their leading dot (e.g., .bashrc, .gitconfig, .tmux.conf).
Now comes the magic of Stow. Navigate to your ~/dotfiles directory in the Terminal. To create symbolic links for a specific set of configurations (e.g., your bash configuration), run the stow command followed by the name of the subdirectory:
cd ~/dotfiles
stow bash
Stow will then look inside the bash subdirectory and create symbolic links in your home directory (~) for each file it finds there. In this case, it would create:
Similarly, to stow your Git configurations, you would run:
cd ~/dotfiles
stow git
This would create:
You can stow multiple configurations at once by listing the subdirectory names:
cd ~/dotfiles
stow bash git tmux
If you need to remove the symbolic links created by Stow (perhaps to test a new configuration or to stop managing a particular set of dotfiles with Stow), you can use the –delete flag:
cd ~/dotfiles
stow --delete bash
This will remove the symbolic links created for the bash configuration. The original files in your ~/dotfiles/bash directory will remain untouched.
Stow is intelligent about handling potential conflicts. If a file already exists in your home directory at the location where Stow wants to create a symbolic link, it will typically refuse to proceed and display an error.
You have a few options when dealing with conflicts: