Pimp my bash console

Andrei Cacio
FineCoding
Published in
1 min readJun 20, 2016

When I first switched from linux to OSX, I’ve noticed that OSX’s default terminal app looks horrifying. I also got used to Linux’s terminal where, out of the box, you have some nifty features, like git autocompletion. So, after a few google searches I stumbled upon some nice tips on how to improve my console experience. After everything was finished I decided to write down all of the steps in this simple tutorial.

First step: install some dependencies

  1. install iTerm
  2. install a sh*t load of color schemes
  3. if you don’t already have one, create a .bash_profile file in your home folder
  4. install git auto completion for your terminal (source)
$ brew install git bash-completion

then add this lines in your .bash_profile file:

if [ -f `brew --prefix`/etc/bash_completion ]; then  
. `brew --prefix`/etc/bash_completion
fi

Next step: add current git branch

function parse_git_branch {  
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\h:\W \u \$(parse_git_branch)\$"

Add some colour variables

insert this in your .bash_profile file.

BLACK=$(tput setaf 0)  
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

Final step

make your console look sexy

export PS1="\[${WHITE}\]\u:\[${BLUE}\]\W\[${NORMAL}\] \$(parse_git_branch)\$

The final .bash_profile file should look like so:

You can copy paste this and see it in action.

Enjoy.

--

--

Andrei Cacio
FineCoding

JavaScript Developer @ Evozon | proud speaker and co-organizer at JSHeroes Community Meetups #javascript #web