Bringing Your Dotfiles Under Version Control - Update
By Saket K
- 4 minutes read - 810 wordsRecently, I was hacking away on my Mac when I stumbled across a dated but still relevant post from 2013 on “How to bring your dotfiles under version control”.
I’m sure this is common practice among most *nix users but I read the post and wondered why I’d never bothered to set things up this way! It sounded ideal to have my most important configuration / personalization files under version control and online so that I could easily set up on a new system.
In a nutshell, the post by ‘Tek Guru’ explains how to move your ‘dotfiles’ (configuration files like .profile, .zshrc or .vimrc) to a separate directory, create a link from your home directory to them (so your applications know where to find them) and then how to set up a git repository to put them under version control. You can then push the repo to Github so you can clone it to any system you like and install your personalized configuration in an instant!
I’m not going to go into the step-by-step here, but since I made a few updates to the way things worked based on my needs, I felt I should describe them for anyone who might be interested.
Updated setup.sh script
In the original post, Tek Guru provides a simple script that creates the symlinks from the home directory to the ‘dotfiles’ directory into which they’d moved the files. For my taste, this script was missing a number of features that I’d like:
- It required you to specify in the script itself which dotfiles you want to symlink
- It hard-coded the paths to the files
Since I was going to make some improvements to the script any way, I re-wrote it and added the following features:
- You can define what you want to call your ‘dotfiles directory’. I defaulted to
~/etc
to stay a little close to *nix conventions - You can define a
.dotfileignore
file in which you can create globs that exclude dotfiles you do not want to include in your version control (things like history files that don’t really need backing up, in my opinion) - It checks to see if you already have a symlink to the file in question and skips over it if it’s already there.
- It gives you a listing of how many new files were processed and how many files were already present.
- TODO: You can specify a
push
parameter indicating whether or not it should commit the changes into git and push them to Github.
DISCLAIMER: Please make sure you back up your configuration files before running this script! I have tested it under very limited conditions on my system and cannot accept any liability if you run the script and it messes up your configurations.
This is the setup_dotfiles.sh
as I have it at the moment:
|
|
The .dotfileignore file looks like this:
|
|