Created
July 13, 2011 21:25
-
-
Save graste/1081370 to your computer and use it in GitHub Desktop.
svn/git repository/branch information in prompt (part of .bashrc)
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
# | |
# SED regexp in parse_svn_repository_root should be different on non-german systems :-) | |
# | |
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_svn_url() { | |
svn info 2>/dev/null | sed -ne 's#^URL: ##p' | |
} | |
parse_svn_repository_root() { | |
#svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p' | |
svn info 2>/dev/null | sed -ne 's#^Basis des Projektarchivs: ##p' | |
} | |
parse_svn_branch() { | |
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk -F / '{print "["$1 "/" $2 "] "}' | |
} | |
parse_git_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
else | |
return 0 | |
fi | |
echo -e "[$gitver] " | |
} | |
branch_color () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
color="" | |
if git diff --quiet 2>/dev/null >&2 | |
then | |
color="${c_green}" | |
else | |
color=${c_red} | |
fi | |
else | |
return 0 | |
fi | |
echo -ne $color | |
} | |
git_status() { | |
if current_git_status=$(git status | grep 'added to commit' >/dev/null 2>/dev/null); then | |
echo "☠" | |
else | |
echo "" | |
fi | |
} | |
PS1='${debian_chroot:+($debian_chroot)}\[$(branch_color)\]$(parse_git_branch)$(parse_svn_branch)\[${c_sgr0}\]\u@\h \[${c_green}\]\w\[${c_sgr0}\]: ' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment