Richard's Ideal Workstation in 2016

 31 March 2016  software-engineering

Yes, it’s time for one of those “here’s how I configure my workstation!” blog posts! A colleague recently asked how what were all those strange aliases I was using - so here’s a full description of how I set up my developer workstation to my idea of near-perfection.

This post assumes using Mac OS X, but 90% of it will be applicable to Linux and other UNIX-like systems too.

The terminal window

Let’s start at the top. iTerm2 - just download it and install it!

Then, configure it so that Alt-Left and Alt-Right can be interpreted by the shell as moving a word to the left or right, as described in this Ask Different answer.

Of course we simply cannot cope with the default colour scheme. We need something more interesting. GitHub user zdj has created a suite of colour themes that can be loaded into iTerm2 (and, as a bonus, also has JetBrains IntelliJ versions too). Check out his repository, then open iterm2 preferences, go to the profiles tab, select your profile and click on the colors tab, click on the load presets drop-down and select import. choose all of the files that are in the iterm2 folder of the git repository.

In case you’re wondering about the font, we’ll change that too, but there’s something else to introduce first.

The shell: zsh, oh-my-zsh and Powerline

Instead of the common default of bash, I prefer zsh. It has quite a few nice features, as described in Why zsh is cooler than your shell (I particularly like slide 29). If you are using MacPorts, it should be as simple as:

sudo port install zsh
chsh -s /opt/local/bin/zsh

Next we’ll install oh-my-zsh, which preconfigures a lot of nice stuff for us. Go to the oh-my-zsh homepage and do what it says under “Install oh-my-zsh now”.

Next open up ~/.zshrc in your favourite editor and start tweaking to your preference. I recommend these settings:

ZSH_THEME="agnoster"
COMPLETION_WAITING_DOTS="true"
plugins=(git common-aliases macports mvn rvm)

…and then under User configuration:

export DEFAULT_USER=richard  # stops agnoster theme showing user@host when logged in as myself on localhost

The agnoster theme will give you a, well, wrong-looking prompt. This is because it needs special fonts to make it look right! The fonts are part of the Powerline project, and you can grab lots of your favourite monospace fonts modified for Powerline from this Git repository. Clone the repository and install your favourite(s).

Open iterm2 preferences, go to the profiles tab, select your profile and click on the text tab, then “Change Font” and choose your preferred font. If you select a Powerline-patched font, then the zsh prompt should now appear perfectly.

Git

This is where it starts to get more interesting. Git is obviously a very flexible tool, and there are numerous possible workflows. A small number of workflows are very popular, in particular the “triangular” workflow that GitHub espouses. What follows are a number of general-purpose Git aliases, along with some that are particularly useful in the triangular workflow.

To start with, check out these blog posts. Most of my funky aliases were cherry-picked (no pun intended) from these posts:

I’ve also added a number of aliases of my own. These ones are simple shortcuts that should be fairly obvious:

fetchall = fetch --all
up = pull --rebase --all
irebase = rebase --interactive
arebase = rebase --abort
crebase = rebase --continue
pick = cherry-pick
co = checkout

I’ve also added some aliases to support the triangular workflow. Remember that in the default Git configuration, each branch has a remote tracking branch, which is the default for git push, pull, rebase, etc. However GitHub goes for a triangular workflow - for pulls I want commits to come from upstream A (which is the canonical repository for a project), but pushes go to upstream B (which is my GitHub fork of the canonical repository). Inspired by this blog post I have added a few more aliases:

triangle = "!f() { git config triangle.from ${1-upstream} ; git config remote.pushdefault ${2-rdowner}; git config push.default current; }; f"

triangle sets up a repository for the next alias. It does this by adding a few config parameters that I just made up. triangle.from is the name of the remote that points to the canonical repository; it defaults to upstream which is the remote name I usually use for the canonical repository. remote.pushdefault - which is a standard Git configuration key - determines where pushes go by default. This defaults to rdowner, which you will probably want to change.

With this alias I can simply run git triangle to set up with the default configuration, or pass explicit parameters like git triangle canonical-upstream my-fork to specify exactly which remote names to use.

The next alias makes use of this:

new = "!f() { from=${2-$( git config --get triangle.from )}; [ -z \"$from\" ] && { echo run git triangle first; exit 1; }; echo creating new branch $1 based off $from/${3-master}; git fetch --all; git branch $1 $from/${3-master}; git checkout $1; }; f"

This creates a new branch. Its remote tracking branch is the master branch of the triangle.from config key that was set by the triangle alias - so by default the new branch will track upstream/master. Any git pull command will pull changes from upstream/master.

Conclusion

That’s the basics on how I configured my workstation. I could go into more detail - vim and IntelliJ IDEA have been customised too - but that’s enough for this blog post.

What do you do with your development environment? Please share your favourite configs, aliases, etc. in the comments below!

 31 March 2016  software-engineering

Comments on this article