Treating hidden files right

August 26th, 2011
[ Linux ]

Warning, this is reasonably geeky stuff but nothing that’ll blow anyone’s minds. I’m a fan of DRY as a principle and I’m lazy.

If you’re on a linux variant then you know how key those wee little hidden files are to your life. I want my dotfiles sync’d across machines. I don’t want to have to mirror changes across machines or cp them onto new installs etc. For that reason I’ve long stored my core dotfiles under version control of some kind, svn, hg, blueturbine, whatever. If you’re not already doing this, please start. Sites like bitbucket offer free private repositories so no excuses.

That handles versioning but what about mirroring etc? In my case, I symlink my dotfiles to wherever that repository is. I keep a simple script to setup those symlinks on new machines.

Here’s an example script. Running this script blows away existing dotfiles on the current machine, by moving them into tmpDir, and creates symlinks to your versioned dotfiles. Now modifying and committing changes in one environment impacts all your setups.

There are a few formal projects out there for this but this simple solution works for me. Related, dotfiles.org is a site for sharing dot files.

# homeDir: home directory where dotfiles are located.
homeDir="/home/guyman"
# configDir: location of actual dotfiles, ie your repository dir.
configDir="/home/guyman/hg/config"
# tmpDir: A temp dir to dump files.
tmpDir="/tmp"

echo "moving any existing files into $tmpDir"
mv $homeDir/.vimrc $tmpDir/.
mv $homeDir/.bashrc $tmpDir/.
mv $homeDir/.ssh/config $tmpDir/.

echo "creating sym links"
ln -s $configDir/.bashrc $homeDir/.bashrc
ln -s $configDir/.vimrc $homeDir/.vimrc
ln -s $configDir/.ssh/config $homeDir/.ssh/config