Skip to content

Instantly share code, notes, and snippets.

@scmx
Created May 9, 2018 12:32
Show Gist options
  • Save scmx/0c04431e58e2998dbf97743a42742fbf to your computer and use it in GitHub Desktop.
Save scmx/0c04431e58e2998dbf97743a42742fbf to your computer and use it in GitHub Desktop.
Bash prompt with Git and autocompletion #bash #prompt #git #complete #autocomplete

Bash prompt with Git and autocompletion

First install HomeBrew and then use brew to install the bash-completion package

brew install bash-completion

After that you can open up your ~/.bashrc file and add the following:

# Load git prompt that display current branch etc
source /usr/local/etc/bash_completion.d/git-prompt.sh

# Define a nice prompt with git prompt inside it
PS1='\[\033[1;34m\]\w\[\033[0;35m\]$(__git_ps1 " (%s)") \[\033[1;36m\]$ \[\033[0m\]'

# Enable bash completion via brew install bash-completion
# It will load all completions defined in /usr/local/etc/bash_completion.d/
if [ -f $(brew --prefix)/etc/bash_completion ]; then
  source $(brew --prefix)/etc/bash_completion
fi

Open up a new terminal Cmd+n and it should be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment