I haven’t posted in a while, been very busy with projects. But here’s a very useful little shell function for getting the URL of a path within a subversion working directory:
function -url
{
info $1 > /dev/null
ERROR=$?
if [ $ERROR -ne 0 ]; then
return $ERROR
fi
info $1 | grep ‘URL: ’ | sed ‘s/URL: //’
}
Put the code into your shell rc file. You could use this function with back ticks like so:
co `-url /path/to/some/working/directory`
- Update: Removed smart quotes.
- Update: Add Daniel Jalkut’s change to the sed statement.
- Update: With the Subversion 1.3 update you can use the –xml switch to output XML that you can then process with xsltproc from the command line:
Save this XSLT file into a well known location (I saved mine into ~/Library/Application Support/Subversion/-url.xslt):
<?xml version=’1.0′ encoding=’utf-8′?> <stylesheet version=‘1.0’ xmlns=‘http://www.w3.org/1999/XSL/Transform’> <output method=‘text’/> <template match="/"> <apply-templates select="/info/entry/url"/> </template> <template match="/info/entry/url"><value-of select="."/><text> </text></template> </stylesheet>Then use it like this:
function -url { info –xml $* | xsltproc "$HOME/Library/Application Support/Subversion/-url.xslt" - }
One big advantage over the previous script is that this new version allows you to use specify wildcards and multiple paths. Of course you’ll need 1.3 though.
Cool! The only problem on my machine was that the output of sed doesn’t strip out the “URL: ” prefix as expected. I managed to get the behavior by changing it to this:
info $1 | grep ‘URL: ‘ | sed ‘s/URL: //’
Also somewhere along the line you got smart quotes in your HTML, so the example won’t work without editing after copy/pasting into an rc file. I fixed it in the line above by using ' instead of the apostrophe character.
Cool! The only problem on my machine was that the output of sed doesn't strip out the “URL: ” prefix as expected. I managed to get the behavior by changing it to this:
info $1 | grep 'URL: ' | sed 's/URL: //'
Also somewhere along the line you got smart quotes in your HTML, so the example won't work without editing after copy/pasting into an rc file. I fixed it in the line above by using ' instead of the apostrophe character.
Thanks for the comment. I removed the smart quotes (looks like ExpressionEngine likes to transform your quotes for you).
I’ll try out the modification to the sed statement and if it works for me too I’ll update the code. Thanks!
Thanks for the comment. I removed the smart quotes (looks like ExpressionEngine likes to transform your quotes for you).
I'll try out the modification to the sed statement and if it works for me too I'll update the code. Thanks!