Skip to content

Instantly share code, notes, and snippets.

@efroese
Created January 18, 2012 16:05
Show Gist options
  • Save efroese/1633746 to your computer and use it in GitHub Desktop.
Save efroese/1633746 to your computer and use it in GitHub Desktop.
# .bash_profile
#####################################################
# Terminal stuff
function parse_git_branch {
git rev-parse --git-dir &> /dev/null
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"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="${LIGHT_RED}⚡"
fi
# 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="${YELLOW}↑"
else
remote="${YELLOW}↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="${YELLOW}↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo " (${branch})${remote}${state}"
fi
}
# Colored ls output
export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad
# export TERM="xterm-color"
export EDITOR=vi
#set -o vi
# Turn off the bell
# xset b 0
BLUE="\[\033[0;34m\]"
CYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"
RED="\[\033[0;31m\]"
MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
WHITE="\[\033[1;37m\]"
ENDCOLOR="\[\033[0m\]"
COLOR1=$CYAN
COLOR2=$GREEN
COLOR3=$CYAN
if [ $UID = 0 ];
then
# I am root
COLOR2="\[\033[0;31m\]"
fi
LONG_PROMPT="$COLOR2($COLOR3\u@$RED\h$COLOR2)\
-($COLOR1$(date +%d-%b-%y)$COLOR2) \
$COLOR2($COLOR3\#$COLOR2) \
$COLOR2($COLOR3\w$COLOR2)$(parse_git_branch)\n \
$COLOR1\$$ENDCOLOR "
NODATE_PROMPT="$COLOR2($COLOR3\u@$RED\h$COLOR2)\
$COLOR2($COLOR3\#$COLOR2) \
$COLOR2($COLOR3\w$COLOR2)$(parse_git_branch)\n \
$COLOR1\$$ENDCOLOR "
SHORT_PROMPT="$COLOR2($COLOR3\u@$RED\h$COLOR2) \
$COLOR2($COLOR3\w$COLOR2)$(parse_git_branch) \n \
$COLOR1\$$ENDCOLOR "
export PS1=$SHORT_PROMPT
function prompt_func(){
PS1="$COLOR2($COLOR3\u@$RED\h$COLOR2) \
$COLOR2($COLOR3\w$COLOR2)$(parse_git_branch) \n \
$COLOR1\$$ENDCOLOR "
}
PROMPT_COMMAND=prompt_func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment