Skip to content

Instantly share code, notes, and snippets.

@mwitek
Created April 3, 2014 16:48
Show Gist options
  • Save mwitek/9958245 to your computer and use it in GitHub Desktop.
Save mwitek/9958245 to your computer and use it in GitHub Desktop.
####################
# Dir colors (barwin custom)
# http://www.mactips.org/archives/2005/08/02/color-your-os-x-command-prompt/
# http://www.macosxhints.com/article.php?story=20031025162727485
export CLICOLOR=1
#export LSCOLORS=fxFxCxDxBxegedabagacad
export LSCOLORS=fxExcxdxbxegedabagacad
###################
##### /LS_COLOR #####
##### PS1 output with colors and git indicators ####
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput sgr0 ; tput setaf 2`
c_sgr0=`tput sgr0`
branch_color (){
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
color=""
if [[ ${git_status} =~ "working directory clean" ]]; then
color="${c_green}"
else
color=${c_red}
fi
else
return 0
fi
echo -ne $color
}
parse_git_bullet (){
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo "•"
fi
else
return 0
fi
}
parse_git_branch (){
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo " (${branch} "
fi
else
return 0
fi
}
parse_git_remote (){
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="On branch ([^${IFS}]*)"
remote_pattern="Your branch is (.*) of"
diverge_pattern="Your branch and (.*) have diverged"
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="↑"
elif [ ${BASH_REMATCH[1]} == "behind" ]]; then
remote="↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo "${remote})"
fi
else
return 0
fi
}
function prompt (){
local WHITE="\[\033[1;37m\]"
local PURPLE="\[\033[0;35m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local DARK_GRAY="\[\033[1;30m\]"
local BLUE="\[\033[0;34m\]"
local bul="\342\200\242"
local EMB="\[\033[1;34m\]"
local EMM="\[\033[1;35m\]"
local EMD="\[\033[0;35m\]"
export PS1="
${EMD}[\T] ${EMM}\W"''${EMB}'$(parse_git_branch)\[$(branch_color)\]$(parse_git_bullet)\[${c_sgr0}\]$(parse_git_remote)'" ${GRAY}"
}
prompt
##### /PS1 output with colors and git indicators ####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment