Pimp Out Your Command Line.

Make your terminal a much cooler place to work in.

Mandy Thomson
6 min readMay 7, 2014

In this post I’m going to show you how to add a theme to your bash shell and how to use aliases to make working in the command line super fast and a lot nicer to look at. This whole process will take about 15 min to set up — totally worth it if you have to do any work from the command line.

The other day I was following this really great tutorial from a fellow Hacker You alumni Jenn Brewer about how to install Oh-My-Zsh. This is a great way to prettify your terminal, however it changes it from the default Bash into Zsh.

What’s the difference between Bash & Zsh? They are both unix shells that do mostly the same things but Zsh has some more features. One day I may want to switch over to zsh, but for now I’m happy with bash — I just needed it to look a lot better!

I came across an awesome little project called Bash-it that does most of the same things that oh-my-zsh does and it’s pretty easy to get it up and running.

TO INSTALL BASH-IT:

First you need to clone the repo by typing this into your command line:


git clone https://github.com/revans/bash-it.git ~/.bash_it

Then Run:

~/.bash_it/install.sh

(this will automatically back up your current ~/.bash_profile into a ~/.bash_profile.bak file)

During the installation it will prompt you for the features you want. I answered ‘some’ to most of the questions so I could choose which plugins and aliases I wanted to enable. I don’t use emacs, nginx and many of the other options so I answered no to those but yes to all the git, node, OSX, gem, grunt, brew and javascript options. Basically just say yes to anything that you use. You can always change these options at a later time too, so don’t worry too much about choosing the wrong things.

This is as easy as going to this site and clicking on the “view raw” to save the font file to your computer. Just click on that file to open it, and then click on the ‘install font’ button in the bottom right corner. Now you need to tell your terminal.app or iTerm to use that font. For terminal you go to the Terminal menu ➜ Preferences ➜ Settings.
For iTerm2 you go to the iTerm menu ➜ Preferences ➜ Text ➜ Change both the Regular Font and the Non-ASCII Font to the one you just downloaded and installed (Anonymice Powerline).

CHOOSE A COLOURFUL THEME:

Now you’ll need to edit your ~/.bash_profile to change the default bash-it theme. Navigate to your computer’s root — for me this is called Mandy. For you it will be whatever you’ve named your mac (hint: it’s got a house icon next to it in the finder.) The .bash_profile file will be greyed out:

If you can’t see this (or any other greyed out files) you’ll have to enable hidden files on your mac.
This is as easy as typing two lines into your terminal:

defaults write com.apple.finder AppleShowAllFiles -boolean truekillall Finder

OK, now that you can see that file go ahead and open it up in sublime text (or whatever other text editor you use). All of the Bash-it theme options can be seen here. The default theme is set to bobby. This is actually a pretty nice theme, but I wanted a powerline theme. To change to your chosen theme, simply edit this line to include your theme’s name.

# Lock and Load a custom theme file
# location /.bash_it/themes/
export BASH_IT_THEME=’bobby’

I could have just changed ‘bobby’ to ‘powerline’ or ‘powerline-plain’ and called it a day, but that’s not really how I roll. I like to customized things with the colours that are pleasing to my eyes. So here’s what I did:

  1. Locate the .bash_it folder in the same place you found your .bash_profile.
  2. Navigate to the themes folder inside and find the theme that you want to customize. Make a copy of that folder and rename it and the file inside. I wanted to customize the powerline theme, so my new folder was renamed to: powerline-m and the file inside was renamed to: powerline-m.theme.bash
  3. Now open both the original theme file and the newly named clone in sublime text.
  4. If you want to customize your own clours, check out this table for colour reference and change the 256 bit colour numbers in your theme file according to your needs.
  5. Make sure you change the theme name in your .bash_profile
# Lock and Load a custom theme file
# location /.bash_it/themes/
export BASH_IT_THEME=’powerline-m’

6. Or just copy mine here:

#!/usr/bin/env bash
# my powerline-m theme
THEME_PROMPT_SEPARATOR=””SHELL_SSH_CHAR=” “
SHELL_THEME_PROMPT_COLOR=39
SHELL_SSH_THEME_PROMPT_COLOR=214
VIRTUALENV_CHAR=”ⓔ “
VIRTUALENV_THEME_PROMPT_COLOR=44
SCM_NONE_CHAR=””
SCM_GIT_CHAR=” “
SCM_GIT_BEHIND_CHAR=”↓”
SCM_GIT_AHEAD_CHAR=”↑”
if [[ -z “$THEME_SCM_TAG_PREFIX” ]]; then
SCM_TAG_PREFIX=”tag > “
else
SCM_TAG_PREFIX=”$THEME_SCM_TAG_PREFIX”
fi
SCM_THEME_PROMPT_CLEAN=””
SCM_THEME_PROMPT_DIRTY=””
SCM_THEME_PROMPT_COLOR=237
SCM_THEME_PROMPT_CLEAN_COLOR=230
SCM_THEME_PROMPT_DIRTY_COLOR=226
SCM_THEME_PROMPT_STAGED_COLOR=206
SCM_THEME_PROMPT_UNTRACKED_COLOR=033
CWD_THEME_PROMPT_COLOR=240LAST_STATUS_THEME_PROMPT_COLOR=197

If you want to change the colour of the main text, the background colours, the cursor colours and more — you do so by going to the iTerm menu ➜ preferences ➜ click on profile ➜ and then then colors tab. If you are using Terminal.app you go to the Terminal menu ➜ preferences ➜ text.

Another thing that you may want to install in your terminal is homebrew. If you don’t already have it, get it — it will make gems and other developer goodies a lot easier to install.

START USING ALIASES IN YOUR COMMAND LINE

You can make aliases for a whole bunch of different functions in the terminal. One of the more useful alias is one that takes you directly into your project directory so you don’t need to manually cd into it. So for example, I made an alias of mmt while I was working on this site. All I had to do was type mmt into my terminal and I was instantly inside my project directory — how awesome is that?!
Here’s how you can do it too:

  1. If you’re using bash ➜ locate your ~/.bash_profile file.
    If you’re using zsh ➜ find your ~/.zshrc file.
  2. Open it in Sublime Text.
  3. Add your alias list to the file. Here’s the syntax:
    alias desired-alias=’linux-command’
  4. You can do some other neat things with an alias too.
# DIRECTORY ALIASES
alias mmt=’cd /Users/Mandy/Desktop/Dropbox/WEBSITES/Portfolio/wp-content/themes/mandy_made_this_theme’
alias tssg=’cd /Users/Mandy/Documents/TELUS/New_WebStandardsStyleGuide’# Open programs from command line
alias sub=’open -a “Sublime Text”’

So that’s it. Now you can see a little more clearly thanks to your new theme and you can do a lot less manual navigating into directories thanks to your new aliases. And that last alias allows you to open files directly from the command line. Let’s say you’re inside a directory that has a readme.txt file in it. Simply type sub readme.txt and the file will open up inside on sublime… Super handy!

Got any other command line tricks? Please leave a comment and share them.

UPDATE:

Thanks to @flipstewart for pointing out that I should turn git colours on. I followed these easy steps to get a base for the colour of my git commands. Then I obviously had to change them all to make them more ‘me’! Here’s my current git colour scheme inside my ~/.gitconfig file:

[color]
ui = auto
[color “branch”]
current = yellow reverse
local = yellow
remote = blue
[color “diff”]
meta = yellow bold
frag = magenta bold
old = white red
new = green bold
[color “status”]
added = yellow
changed = black magenta
untracked = black cyan

--

--

Mandy Thomson

Mandy is a TV Editor + Digital Creative Director + Front-End Developer/Designer in Toronto, ON. She tweets at @fixmysync