Skip to content

Instantly share code, notes, and snippets.

@anujbiyani
Created September 21, 2018 00:32
Show Gist options
  • Save anujbiyani/b1fa76cea1a1daf491a02910307a40ac to your computer and use it in GitHub Desktop.
Save anujbiyani/b1fa76cea1a1daf491a02910307a40ac to your computer and use it in GitHub Desktop.
Add this to your ~/.bash_profile to get the git branch (and some coloring for your prompt)
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
## ANSI color codes
RS="\[\033[0m\]" # reset
HC="\[\033[1m\]" # hicolor
UL="\[\033[4m\]" # underline
INV="\[\033[7m\]" # inverse background and foreground
FBLK="\[\033[30m\]" # foreground black
FRED="\[\033[31m\]" # foreground red
FGRN="\[\033[32m\]" # foreground green
FYEL="\[\033[33m\]" # foreground yellow
FBLE="\[\033[34m\]" # foreground blue
FMAG="\[\033[35m\]" # foreground magenta
FCYN="\[\033[36m\]" # foreground cyan
FWHT="\[\033[37m\]" # foreground white
BBLK="\[\033[40m\]" # background black
BRED="\[\033[41m\]" # background red
BGRN="\[\033[42m\]" # background green
BYEL="\[\033[43m\]" # background yellow
BBLE="\[\033[44m\]" # background blue
BMAG="\[\033[45m\]" # background magenta
BCYN="\[\033[46m\]" # background cyan
BWHT="\[\033[47m\]" # background white modifying prompt
# https://github.com/jimeh/git-aware-prompt
find_git_branch() {
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch=' detached*'
fi
git_branch=" ($branch)"
else
git_branch=""
fi
}
find_git_dirty() {
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
git_dirty=' *'
else
git_dirty=''
fi
}
PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
PS1="$HC$FBLE$FGRN\w$FWHT\$git_branch$FRED\$git_dirty $HC$FBLE\$ $RS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment