Krzysztof Kaczor

Passionate Software Developer

Use terminal like a boss

on 26. January 2016

Even in 21st century terminal is still programmer’s best friend - we use it extensively every day. That is why it’s important to make it as useful and productive as it can be.

In this article I am gonna to present few ideas to make interaction with terminal easier. It is directed to OS X users but general ideas can be useful on linuxes as well.

iTerm + zsh + ohmyzsh

Install and learn how to use this stuff. It is as simple as this. It will give you much power just by installing it and following readme instruction. Select nice theme and set up useful plugins for you. Here’s my list (it makes startup of new session much slower so you rather want to make it short):

 plugins=(git npm grunt jira virtualenvwrapper)

And don’t forget to setup aliases for most common commands:

alias ll="ls -AlFh"
alias npmI="npm install"
alias npmG="npm install --global"
...

Take a look at awesome zsh for inspiration.

Reduce context switching

One of the most annoying things for me is context switching between applications. When I use IDE and then switch to terminal I don’t want to think what keyboard shortcut should I use to paste from clipboard (on OS X you can always use CMD + C but it’s not that obvious on linux running on normal PC). That is why I tend to configure all shortcuts in my system in consist way and this is why you should configure shortcuts in iTerm to mimic normal text editor. By adding shortcuts like CMD + arrow keys, CTRL + arrow keys navigating around input line will be as easy as navigation in vim ;)

Optimize common operations

Pasting

Very common operation is pasting commands directly from internet. We want to make it almost ready to apply (delete unnecessary characters) but block it from automatically running (it can happen when you copy whole lines). That’s why it’s very good idea to override default paste command with something similar to this:

pbpaste | sed -E "s/\\\$[[:space:]]*//" | awk '{printf} {printf " && "} END {}'| rev | cut -c 5- | rev | tr -d "\n"

Pasting something like

npm install
bower install
gulp serve

will result with

npm install && bower install && gulp serve

without running it so you can read command and tweak it if necessary.

Password management

If you don’t know/use 1password or something similar stop reading this article and install it ASAP ;) Once you done it, install sudolikeaboss to be able to easily paste your passwords directly into shell. It’s huge boost for “sudo’ing” on external servers.

Summary

These were my most favorite tips for using terminal on OS X. Have something interesting to add? Let me know on twitter.