Skip to content

Instantly share code, notes, and snippets.

@scicco
Last active July 5, 2016 08:30
Show Gist options
  • Save scicco/4985126 to your computer and use it in GitHub Desktop.
Save scicco/4985126 to your computer and use it in GitHub Desktop.
git.bashrc
# ~/.bashrc
# tab-completion for git subcommands
# (this is for git installed via MacPorts: `sudo port install git-core +svn`)
#source /usr/local/Cellar/git/1.7.6/etc/bash_completion.d/git-completion.bash
# git status with a dirty flag
function __git_status_flag {
git_status="$(git status 2> /dev/null)"
remote_pattern="^# Your branch is (.*) of"
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="⚡"
spacer=" "
fi
if [[ ${git_status} =~ ${remote_pattern} ]]; then
spacer=" "
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="↑"
else
remote="↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="↕"
spacer=" "
fi
echo "${state}${remote}${spacer}"
}
# the prompt itself
PS1='\[\e[32m\]\u@\[\e[1m\]\h\[\e[22m\]:\[\e[1;34m\]\w\[\e[22;33m\]$(__git_ps1 " [\[\e[31m\]$(__git_status_flag)\[\e[33m\]%s]")\[\e[33m\] \$ \[\e[0m\]'
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
@scicco
Copy link
Author

scicco commented Jul 5, 2016

copy this under your home and add this into your ~/.bash_profile

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

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