Managing dotfiles with GNU stow

It’s often convenient to have all of your dotfiles in one place, so they can be transported and version-controlled. In reality however, they are scattered in various subdirectories of your home folder. I recently learned how to use GNU stow to reconcile this.

In short, stow solves this problem by throwing symlinks where the dotfiles/folders should be found. This allows you to keep the real files bottled up in one directory. In order to place these symlinks, stow uses the concept of source and target directories. By default, the source directory is the current dir, and the target directory is the parent of the source. Here is a typical setup used to populate symlinks with stow:

~/
    dotfiles/          # run stow and version control here
        openbox/       # each "package" gets a special subdirectory
            .config/
                openbox/
                    rc.xml
                    menu.xml
    .config/
        openbox/
            ...     # empty dir, ready for symlinks
    

To create the symlinks, you would run `stow openbox` in the ~/dotfiles directory. You’ll notice, each “package” in ~/dotfiles has it’s own subdirectory. Since we ran stow with the parameter “openbox”, stow will effectively use ~/dotfiles/openbox as the “true” source directory. This is purely for organizational purposes, and helps keep your applications seperate. After that command, your tree will look like this:

~/
    dotfiles/
        openbox/
            .config/
                openbox/
                    rc.xml
                    menu.xml
    .config/
        openbox/
            rc.xml -> ../../dotfiles/openbox/.config/openbox/rc.xml
            menu.xml -> ../../dotfiles/openbox/.config/openbox/menu.xml
    

A few closing notes:

  • Stow will not overwrite existing files in your target dir. It will throw file conflict errors.
  • Stow will not create new directories in your target dir. Intead, it will place a symlink to the entire folder tree in your source dir.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s