For me, managing all of my dotfiles across my different computers used to be a difficult and time-consuming task. Using GNU Stow, I can now manage all of my dotfiles in a centralized directory. A centralized directory offers the convenience of:
- organizing my dotfiles into seperate directories, based on their function
- version-controlling my dotfiles on GitHub
For example, I have all my vim
related dotfiles stored in a directory aptly named vim
. This directory contains anything vim
related, so that includes files like .vimrc
, the .vim
directory, etc. I have similar directories for zsh
, bash
, tmux
, etc. Version-controlling is easily achieved by initializing the centralized dotfiles directory as a git repository, and pushing/pulling your changes via GitHub. This is very easy to do, as all of your dotfiles are now contained within one main directory.
If you just want to use my setup, then just follow this setup. BE CAREFUL though, as if you perform these commands, your existing dotfiles will get overwritten with the ones in this repository. You can have stow
prevent overriding files by running the commands below without the -R
option (ex. stow -vt ~/ bash
).
If you dont care about this, then here is the quick and simple way to get my setup:
cd path/to/dotfiles_repo
stow -vRt ~/ bash
stow -vRt ~/ zsh
...
You can repeat the stow
command for any number of packages you want. Additionally, if you would like for stow
to install the package under a different directory other than the home directory, then just replace the ~/
directory with the directory of your choice.
The cron
package contains one file called cronjobs
. This file contains a list of jobs that I let cron
schedule and run. Anytime I make a change to the cron/cronjobs
file, or if I'm adding my dotfiles to a new computer, I run the following command to refresh my crontab
:
crontab cron/cronjobs
Managing your own dotfiles using stow
is also very easy:
- Create a new directory to hold your dotfiles. I created one by doing
mkdir ~/git/dotfiles
. - Create a directory for each of the different dotfile types you plan on storing. For example, I plan to store and manage my
vim
,bash
, andtmux
dotfiles using stow, so I'll domkdir ~/git/dotfiles/vim ~/git/dotfiles/bash ~/git/dotfiles/tmux
.stow
refers to each of these directories as apackage
. So~/git/dotfiles/vim
is really astow
package for yourvim
dotfiles. - Move all your dotfiles to the new directories that they belong in. For example, I'll be moving my
.bashrc
,.bash_profile
, and.profile
files into~/git/dotfiles/bash/
, and move my.vimrc
and.vim
directory into~/git/dotfiles/vim/
. - The next step involves using the magic of
stow
. MAKE SURE you are in your root dotfiles directory, which for me is~/git/dotfiles
. You should be able to see all of your packages by runningls
. We'll use thevim
package for this example. When you executestow
, what it will do is create symlinks to all the files and directories stored in thevim
package in a pre-defined directory. In myvim
package I have avimrc
file and a.vim
directory containing a bunch ofvim
related files. Executingstow -vRt ~/ vim
will create symlinks to.vimrc
and.vim
in the~/
directory. TheVIM
editor can now reference myvim
dotfiles, since it reads from~/.vimrc
, which points to my dotfiles directory. I can also edit~/.vimrc
as I normally would and have the changes appear in~/git/dotfiles/vim
. - After stowing all your packages, initialize your dotfiles repository as a git repository. For example, I will do
git init ~/git/dotfiles
. Create a repository on GitHub, or whatever hosting service you prefer, and set up yoru local dotfiles repository to point to the remote GitHub repository. Then commit and push your changes. - Now you can clone your GitHub dotfiles repository on your other computers. After cloning, just perform
stow -vRt <target_dir> <package>
on all your packages to bring over your dotfiles. BE CAREFUL as this will override any of your local dotfiles, so make sure you copy and save them to a safe location if you are at all worried about losing your old copies. Any time you make any dotfile changes on any of your computers, just commit and push, and then pull these changes on your other computers and restow
the package. Very simple!