Handy svn shell aliases and functions
If you know me very well, you know I’m a Unix geek. I cannot work efficiently without a Unix shell so when I’m in Windows I install Cygwin as soon as I can and use Cygwin tools over native Windows tools as often as I can. That is how far my Unix Shell addiction goes.
Lately I’ve been trying to put useful one-liners into shell functions and aliases so I can easily use them again and again and again without having to remember the syntax. I use svn on the command line and have come up with. All of these were written in Z-Shell but should work in Bash, etc.
The source of my projects are in a directory called, appropriately, “src”. These aliases saves me some typing trying to figure out the status of the source folder:
alias srcstatus="svn status src"alias srccommit="svn commit src"
I also tend to forget to add new source files to the repository before committing it. This command does a srcstatus, finds the new files, and adds them to the repository — all in one line. This one seems to work better as a function. I’m not sure why:
function addsrcs() { srcstatus|egrep "^?"| awk '{print $2}'|xargs svn add}
June 25th, 2007 at 10:38 am
Always nice to see other zsh users! My latest svn related shell function is:
function svnstat() {
tmpfile=/tmp/svn-diff.$$
svn diff "$@" > $tmpfile
typeset -i added removed delta
added=$(grep '^+' $tmpfile | wc -l)
removed=$(grep '^-' $tmpfile | wc -l)
delta=$((added - removed))
if [ $delta -lt 0 ]; then
deltachr=”-”
elif [ $delta -eq 0 ]; then
deltachr=” ”
else
deltachr=”+”
fi
svn status
echo ” + ${added} lines”
echo ” - ${removed} lines”
echo ” ${deltachr} ${delta} lines overall”
rm -f $tmpfile
}