Customize bash in Mac terminal to show version control information

Highlights: I came across nice utility vcprompt which shows the git source control information in Mac OS bash terminal.

Steps:
Install vcprompt using brew
brew install vcprompt

Now Add this code in .bashrc file in your home directory
You can search for different colors and use those as variables with “$” prefix.
You can pass different format options for vcprompt -f flag.

NO_COLOR='\e[0m'
RED='\e[0;31m'
export PS1="\n\u:\w \[$RED\] \$(vcprompt -f [%b])\[$NO_COLOR\] \n→ "

Once you are done with above changes, either restart the terminal or run the command to load configuration file.

source ~/.bashrc

Result: Now You will see the project current branch and other information when you navigate to a folder which is under source control.

Autocompletion for git commands

Requirement: it would be great to get autocompletion for git commands in mac terminal.

Install Git download

Now we need to download bash file with all commands. Open terminal and run this command from Home directory.

curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash .git-completion.bash

Now check for .bash_profile in your home directory. open terminal
This command should show all invisible file also.

ls-a

Create file .bash_profile if it doesn’t exist.

touch .bash_profile

Open file .bash_profile in text editor or editor of your choice.

open .bash_profile

Now append this code for .bash_profile file.


if [ -f ~/.git-completion.bash ]; then
    . ~/.git-completion.bash
fi

Save it and close the terminal.

Verify:
Open the terminal.
type > git h
This should complete command as “git help”

Verify 2:

You can get completion for git command options also.
git log –a
this should list all possible options start with “–a”.