Skip to content

Instantly share code, notes, and snippets.

@icodeforlove
Created November 30, 2012 23:20
Show Gist options
  • Select an option

  • Save icodeforlove/4179410 to your computer and use it in GitHub Desktop.

Select an option

Save icodeforlove/4179410 to your computer and use it in GitHub Desktop.
bash_profile functions for additional repo info
parse_git_branch() {
slashes=${PWD//[^\/]/}
directory="$PWD"
path=false
if [ -d ".git" ]; then
path="."
else
for (( n=${#slashes}; n>0; --n )) do
test -e "$directory/.git" && path="$directory"
directory="$directory/.."
done
fi
[ $path != false ] && git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'
}
parse_hg_changeset() {
slashes=${PWD//[^\/]/}
directory="$PWD"
path=false
if [ -d ".hg" ]; then
path="."
else
for (( n=${#slashes}; n>0; --n )) do
test -e "$directory/.hg" && path="$directory"
directory="$directory/.."
done
fi
[ $path != false ] && cat "$path/.hg/cache/branchheads" | awk 'NR == 1' | sed -e 's/.*\ //g' -e 's/^/ r/' -e 's/$//'
}
# colors
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\e[1;32m\]\u \e[1;36m\]\w\e[1;33m\]$(parse_git_branch)$(parse_hg_changeset)\[\e[0m\]\n# \[\e[0m\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment