Created
March 9, 2012 03:28
-
-
Save weikinhuang/2004856 to your computer and use it in GitHub Desktop.
Bash PS1 git and svn repo info
This file contains hidden or 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
# Special repo status function for git and svn | |
__repo_ps1 () { | |
local info=$(svn info 2> /dev/null) | |
# if not a svn repo, then try the git method | |
if [[ -z "$info" ]] ; then | |
echo -n "$(__git_ps1)" | |
return | |
fi | |
# if it is a svn repo, then strip info out of it | |
local svnrev=$(echo "$info" | awk '/Revision:/ {print $2}') | |
local flag= | |
# if we want to show dirty state then exec svn status | |
if [ $SVN_PS1_SHOWDIRTYSTATE ] ; then | |
local state=$(svn status --ignore-externals "$(echo "$info" | sed -n "s/Working Copy Root Path: \(.\+\)/\1/p")" 2> /dev/null) | |
# make the file status conditions unique if there are changes | |
if [ -n "$state" ]; then | |
flag=" *"$(echo "$state" | awk '{print $1}' | uniq | sort | tr -d '\n') | |
fi | |
fi | |
echo -n " ($svnrev$flag)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment