Dotfiles 2

Dotfiles are a fantastic way to centralize your configuration files for various tools and utilities. Examples of these include Git, Vim and Shells such as Bash, Zsh and Fish.

I have been using holmon’s dotfiles for a while and it has been really good. It comes some nice tweaks and a bootstrap script which symlinks everything with the suffix ‘.symlink’.

But I wanted to have a go at making my own from scratch, also I wanted to add homebrew and casks into an install script so it installed everything for me.

I took inspiration from webpro’s installation & update scripts and created two of my own:

Install assumes a clean OSX install, setting some OSX defaults, installing all the apps and tools I use finishing with symlinking my configuration files.

Update is a convenience script which updates homebrew, npm, and ruby packages as well as a few other chores. I usually fire this off in the morning while I make a cup of coffee, when I come back I know everything is up to date which is nice :)

brew.sh, npm.sh and gem.sh

I use npm and ruby gems to install any official packages (eg Sass/Bower) and homebrew for tools and apps such as Git and Google Chrome. These files just have a list like the one below which I can add to whenever. It also checks to see if it’s installed it before which is kind of a poor mans idempotent but it works!

packages=(
    brew-cask
    fish
    git
    mysql
    node
    php56
    composer
)

apps=(
    alfred
    atom
    google-chrome
)

Atom Editor

I’ve recently started using Atom again and stumbled across their package manager APM. This allows you to install packages from the command line, and even includes an option to read a list of packages to install from a text file. This was brilliant because it meant I could just tell atom to grab the latest plugins and themes.

Git

In my original dotfiles I had a prompt which asked me to put in my git name and email. While this is cool it was a bit of a pain to be asked this every time I ran install so I sought inspiration from symfony and created a secrets file.

#!/usr/bin/env fish

# git config --global user.name ""
# git config --global user.email ""

I also learned you could also include other git config files in your global config and the same for the excludes file. This meant I didn’t have to symlink my git config and could simply link to it (a win for simplicity!). My non dotfiles git config actually looks quite minimal:

[include]
	path = /Users/rob/.dotfiles/git/.gitconfig
[core]
	excludesfile = /Users/rob/.dotfiles/git/.gitignore

Of course none of this worked first time, it never does! In fact it didn’t even work flawlessly the second time but such is the joy of coding! I learned a lot doing this and definitely pleased I did it. Before it took me up to a day to set up my mac with all my apps ect but with this it took me just over an hour.

If you’d like to learn more about dotfiles please check out the wiki page which has loads of links on the subject. Also you can check out my dotfiles on Github

Thanks for reading