Created
May 24, 2012 18:02
-
-
Save efroese/2783158 to your computer and use it in GitHub Desktop.
Erik Bash Git Goodness
This file contains 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
# .bash_profile | |
# set -xv | |
##################################################### | |
# each shell appends to history | |
shopt -s histappend | |
PROMPT_COMMAND='history -a' | |
export HISTFILESIZE=1000000000 | |
##################################################### | |
# Terminal stuff | |
function parse_git_branch { | |
[ -d .git ] || return 1 | |
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="*" | |
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="↑" | |
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 " (${branch}${state}${remote})" | |
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\]" | |
LIGHT_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