Lots of nights and years of potential productive work have programmers have lost, by procrastinating on configuring their dotfiles. These simple invisible files may seem pointless for a novice, but in the hands of an expert they become a swiss army knife. I'm no exception and I've used the occasion of receiving a new laptop for learning more about Ansible and tweaking those files.

Ansible

Is an open-source platform for configuring and managing computers. Usually ops people use it  to configure farms of servers. You need to be able to spin up dozens of machines, and configure them to be load balancers, db nodes, web apps or whatever is your need. But you can also configure your laptop using them. Puppet and Chef are the other rivals, each with their own pros and cons.

I prefer to view all these tools like "Bash on steroids". You could in theory do the same things by writing a script file that installs the dependencies, copies the configurations and starts the services. But what happens if the script fails in the middle? Now you have to take into account that you have to re-run your script, and must force copying the files you did already. And how do you know your packages installed successfully? Instead of writing a bunch of ifs in a shell script, why not use a proper tool.

For configuring a Mac machine you can also use Boxen from Github (written in Puppet), Kitchenplan (written in Chef), Battleschool (written in Ansible) or lots of other tools. I've written my own playbooks because I wanted to learn Ansible :-)
Ansible provisioning my laptop

My .vimrc

There was once a time when I used to spend my life in VIM. But now, it's only the occasionall tinkering with /etc/hosts or opening another configuration file that makes me use it.

My most used shortcut by far is:

cmap w!! w !sudo tee % >/dev/null

Every time you forget to sudo before opening a file and you do not have the rights to save it, you just :w!!, write the superuser password and the file gets saved. No more copying your code to another file, exiting the current process, opening another one with sudo, pasting everything, maybe indenting... you get the point.

Every plugin installs using the wonderful Vundle.vim plugin. You just specify what you want to install, and it fetches it for you. An Ansible play also updates all your plugins, so you live every day on the bleeding edge.

My VIM terminal, with NERDTree and CtrlP opened

ZSH shell

If you are still using Bash, you are living under a rock, seriously. Start reading the top articles from the Hacker News crowd. You don't need to read heavy manuals to use it. The shell feels for me natural. I also use oh-my-zsh, which has lots of plugins, some nice defaults and you can get inspired to build your own theme. The .zshrc file is only ~80 lines and has nothing esoteric in it.

My prompt is pretty basic, but I love to have the Git branch in front of my eyes.

tmux vs iTerm2

I once used tmux to manage my terminal windows. You SSH into a remote machine, start a session and can arrange 4 split screen windows. If your Internet connection stops, you can SSH back and attach to the same session.

But since the Internet connection in Bucharest is solid, and my remote machines are on AWS or DigitalOcean, I just don't need another layer between my terminal app and the shell. But I use iTerm2 to manage my N terminals setup split up on the whole screen, where N tends to be > 5 on some days.

FASD

The most used tool in the shell by me is by far FASD. It compiles a list by using frecency (frequency and recency) of the directories and files, and it starts reading my mind. If I type z feature it will change the directory to ~/uberVU/thehole/ubervu/frontend/features and if I type v mac it will open ~/dotfiles/playbooks/tasks in Vim. It's my best command line productivity booster, since I've found myself moving between directories all the time.

HomeBrew and Brew Cask

Every programmer that has migrated from the Linux world to the OSX world knows that Apple devies do not have a proper package manager like apt. We use Brew to install and compile formulas, which means a Ruby installation will take 5-6 minutes and will make your fan to produce a lot of heat. But, it's better than nothing.

Brew Cask is an attempt to package user apps and install them in batch from the command line. It just works and in minutes you have Spotify, Chrome and other apps installed and symlinked to /Application.

Playbooks

Are simple YAML files. Here is the sublime_text.yml which extensively uses the file module. There are also modules for git, apt, homebrew, pip, raw commands or whatever you may need to configure and deploy a machine.
---
- name: Remove Sublime config dir if it exists
file: path=~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User
state=absent

- name: Symlink Sublime Text config
file: src=~/dotfiles/configs/sublime_text_3/User
dest=~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User
force=yes
state=link

- name: Symlink Sublime Text to subl in terminal
file: src=~/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
dest=/usr/local/bin/subl
state=link

I've written a list of tasks and split them in 2: a playbook executes the tasks that I need to provision a Macbook, and another playbook that I use to provision tools on a remote Ubuntu machine or on Vagrants.

In writing this article and configuring my machine, I was inspired by:
You can talk about this article on the HN thread. Some people have suggested there their way of managing the "dotfiles hell".

If you liked this article, you may like how I try to automate my mundane tasks dev tasks.