Created
August 19, 2010 18:13
-
-
Save dtjm/538522 to your computer and use it in GitHub Desktop.
Subversion PS1 prompt functions for bash
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
# | |
# If you want to see svn modifications: | |
# export SVN_SHOWDIRTYSTATE=1 | |
# | |
# Put this in your PS1 like this: | |
# PS1='\u@\h:\W\[\033[01;33m\]$(__git_svn_ps1)\[\033[00m\]$ ' | |
# Git/Subversion prompt function | |
__git_svn_ps1() { | |
local s= | |
if [[ -d ".svn" ]] ; then | |
local r=`__svn_rev` | |
local b=`__svn_branch` | |
s=" [$b:$r]" | |
elif [[ -d .git ]] ; then | |
s=`__git_ps1` | |
fi | |
echo -n "$s" | |
} | |
# Outputs the current trunk, branch, or tag | |
__svn_branch() { | |
local url= | |
if [[ -d .svn ]]; then | |
url=`svn info | awk '/URL:/ {print $2}'` | |
if [[ $url =~ trunk ]]; then | |
echo trunk | |
elif [[ $url =~ /branches/ ]]; then | |
echo $url | sed -e 's#^.*/\(branches/.*\)/.*$#\1#' | |
elif [[ $url =~ /tags/ ]]; then | |
echo $url | sed -e 's#^.*/\(tags/.*\)/.*$#\1#' | |
fi | |
fi | |
} | |
# Outputs the current revision | |
__svn_rev() { | |
local r=$(svn info | awk '/Revision:/ {print $2}') | |
if [ ! -z $SVN_SHOWDIRTYSTATE ]; then | |
local svnst flag | |
svnst=$(svn status | grep '^\s*[?ACDMR?!]') | |
[ -z "$svnst" ] && flag=* | |
r=$r$flag | |
fi | |
echo $r | |
} |
I did the regex on L30 a little different; sed apparently can't do non-greedy regexes so I used perl instead:
elif [[ $url =~ /branches/ ]]; then
echo $url | perl -pe 's|^.*/branches/(.*?)/.*$|\1|'
This made it so only the branch name was displayed, not the branch and remaining path to CWD.
I also added @pestophagous __svn_info_str method. I'm on a pretty old version of SVN though (1.8.9)
A key feature of the changes introduced in Subversion 1.7 is the centralization of working copy metadata storage into a single location. Instead of a .svn directory in every directory in the working copy, Subversion 1.7 working copies have just one .svn directory—in the root of the working copy.
From: https://subversion.apache.org/docs/release-notes/1.7.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@adamjstewart I tried your method, but your
__svn_ps1()
hangs for me (on SunOS 5.10 with SVN 1.8.9.... given my environment, don't take my report seriously)