Skip to content

Instantly share code, notes, and snippets.

@kevinclark
Forked from matthewmccullough/gist:47267
Created February 9, 2011 20:39
Show Gist options
  • Save kevinclark/819229 to your computer and use it in GitHub Desktop.
Save kevinclark/819229 to your computer and use it in GitHub Desktop.
Tweaked to do relative dirs in git repos
alias git=hub
alias g='git'
alias go='git checkout'
alias irc='ssh glu.ttono.us'
alias clj='java jline.ConsoleRunner clojure.main'
alias la='ls -a'
alias ll='ls -alF'
export EDITOR='mvim -f'
export PATH="/Users/$(whoami)/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql83/bin:$PATH"
export P4CONFIG=.p4config
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
export CLASSPATH="/Users/kev/code/jars/*:/opt/jars/*"
export OOC_DIST=/Users/kev/code/ooc
# Initialize the 'hop' script
source /Users/$(whoami)/twisted_env/bin/../hop/hop.bash
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
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="${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
}
function parse_wd {
repodir="$(git rev-parse --show-toplevel 2> /dev/null)"
previous_return_value=$?;
cwd="$(pwd)"
if test $previous_return_value -eq 0; then
if [[ ! ${repodir} == ${cwd} ]]; then
relativedir="$(ruby -e 'puts ARGV[1].split(ARGV[0])[1]' $repodir $cwd)"
echo $YELLOW$(basename $repodir) $COLOR_NONE$relativedir
else
echo $YELLOW$(basename $repodir)
fi
else
echo $RED$cwd
fi
}
function prompt_func() {
previous_return_value=$?;
# prompt="${TITLEBAR}$BLUE[$RED\w$GREEN$(__git_ps1)$YELLOW$(git_dirty_flag)$BLUE]$COLOR_NONE "
prompt="${TITLEBAR}${BLUE}[${COLOR_NONE}$(parse_wd)${GREEN}$(parse_git_branch)${BLUE}]${COLOR_NONE} "
if test $previous_return_value -eq 0
then
PS1="${prompt}➔ "
else
PS1="${prompt}${RED}➔${COLOR_NONE} "
fi
}
PROMPT_COMMAND=prompt_func
@kevinclark
Copy link
Author

Adds yellow for current repo with white for relative dir OR red for a non-git repo

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