Created
May 5, 2012 06:00
-
-
Save bosky101/2600221 to your computer and use it in GitHub Desktop.
Place this in your .bash_profile for git-completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Command line prompt addon, to autocomplete git commands & branches | |
# as well as show current branch. It is especially useful since it modifies | |
# the terminal prompt & uses colors to distinguish if master is dirty | |
# or the working directory is up to date | |
# | |
# Step 1 | |
# get git-completion.bash from any git repo | |
# https://raw.github.com/git/git/master/contrib/completion/git-completion.bash | |
# Step 2 | |
# open your .bash_profile and add the following one line | |
# source $HOME/bashs/git-completion-addons.bash | |
# | |
# Here is the contents of git-completion-addons.bash | |
# | |
source $HOME/bashs/git-completion.bash | |
# color coding directories as brown, executables as red | |
export CLICOLOR=1 | |
export LSCOLORS=DxFxCxDxBxbgedabagacad | |
#export PS1='\h:\W$(__git_ps1 "(%s)") \u\$ ' | |
# git terminal prompt hacks | |
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_git_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
else | |
return 0 | |
fi | |
echo -e $gitver | |
} | |
branch_color () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
color="" | |
if git diff --quiet 2>/dev/null >&2 | |
then | |
color="${c_green}" | |
else | |
color=${c_red} | |
fi | |
else | |
return 0 | |
fi | |
echo -ne $color | |
} | |
export PS1='[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]] \u@\[${c_red}\]\w\[${c_sgr0}\]$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment