How we work

Configure Command Prompt

These days we use git in most of our projects. If we are using git 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.

1$ ~/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.

1$ 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.

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

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

1txtblk='\e[0;30m' # Black - Regular
2txtred='\e[0;31m' # Red
3txtgrn='\e[0;32m' # Green
4txtylw='\e[0;33m' # Yellow
5txtblu='\e[0;34m' # Blue
6txtpur='\e[0;35m' # Purple
7txtcyn='\e[0;36m' # Cyan
8txtwht='\e[0;37m' # White
10bldblk='\e[1;30m' # Black - Bold
11bldred='\e[1;31m' # Red
12bldgrn='\e[1;32m' # Green
13bldylw='\e[1;33m' # Yellow
14bldblu='\e[1;34m' # Blue
15bldpur='\e[1;35m' # Purple
16bldcyn='\e[1;36m' # Cyan
17bldwht='\e[1;37m' # White
19unkblk='\e[4;30m' # Black - Underline
20undred='\e[4;31m' # Red
21undgrn='\e[4;32m' # Green
22undylw='\e[4;33m' # Yellow
23undblu='\e[4;34m' # Blue
24undpur='\e[4;35m' # Purple
25undcyn='\e[4;36m' # Cyan
26undwht='\e[4;37m' # White
28bakblk='\e[40m'   # Black - Background
29bakred='\e[41m'   # Red
30badgrn='\e[42m'   # Green
31bakylw='\e[43m'   # Yellow
32bakblu='\e[44m'   # Blue
33bakpur='\e[45m'   # Purple
34bakcyn='\e[46m'   # Cyan
35bakwht='\e[47m'   # White
37txtrst='\e[0m'    # Text Reset
39a="\n$txtwht\u$txtblu \w $txtpur"
40e="$\[\033[00m\] "
42function parse_git_url {
43  git config --get remote.origin.url | sed 's/\.git$//;s/\(.*[:/]\)\([^/]*\)\/\([^/]*\)\(\.git\)\{0,1\}$/(\2\/\3)/'
46function parse_git_branch {
47  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
50function custom_git_prompt {
51  branch=$(git branch 2> /dev/null) || return
52  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 anything else.