How we work

Configure Command Prompt

These days we use git in most of our projects. If we are using git then then it's a good idea to know which branch we are working on. We can check what our current branch is but it would be much nicer if the command prompt displays the current branch automatically.

Here is how your command prompt would look after the instructions mentioned in this page are followed. Note that the current branch (master) is displayed in the command prompt along with the directory name.

$ ~/code/bigbinary-website master

Configurations of Custom Command Prompt

These instructions will work only if you are using bash shell.

First let's create ~/.bashrc file if it does not exist.

$ touch ~/.bashrc

On command prompt execute code ~/.bash_profile. Copy the existing content in clipboard.

Now execute code ~/.bashrc. Past the content from ~/.bash_profile to the bottom of ~/.bashrc file.

Now delete all the contents of ~/.bash_profile.

Now put the following code in ~/.bash_profile.

if [ -f ~/.bashrc ]; then
    source ~/.bashrc

Now open ~/.bashrc and add the following content at the bottom of the file.

txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White

bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White

unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White

bakblk='\e[40m'   # Black - Background
bakred='\e[41m'   # Red
badgrn='\e[42m'   # Green
bakylw='\e[43m'   # Yellow
bakblu='\e[44m'   # Blue
bakpur='\e[45m'   # Purple
bakcyn='\e[46m'   # Cyan
bakwht='\e[47m'   # White

txtrst='\e[0m'    # Text Reset

a="\n$txtwht\u$txtblu \w $txtpur"
e="$\[\033[00m\] "

function parse_git_url {
  git config --get remote.origin.url | sed 's/\.git$//;s/\(.*[:/]\)\([^/]*\)\/\([^/]*\)\(\.git\)\{0,1\}$/(\2\/\3)/'

function parse_git_branch {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'

function custom_git_prompt {
  branch=$(git branch 2> /dev/null) || return
  echo "$(parse_git_branch)"


Now quit your shell and start a new shell. You should see a new command prompt.

Customize to your choice

Now that your custom command prompt is working it's time to customize it. You can change the color, font size or anythng else.

Got a project in mind?