Filtering SVN Status results

I frequently have to run the svn status using a pipe to grep for filtering only specific svn flags (A, M, G, ? ...). However I got board and made a script so I can pipe the output of svn status, to my handy little script to make life easier

#!/bin/bash
#
# This script is usefull for when checking so status
#
# @author: Shahmir Javaid

#Run the `tty` command and exit if the `so` command was run directly for terminal
#This is to make sure, that `so` command is only ran as a piped command
if [ "$( tty )" != 'not a tty' ]; then
    echo "'so' needs to be piped, Works best with 'svn status | so'"
    exit 1
fi

if [ $# -eq 1 ]; then
    CATRET=`cat - | egrep "^["$1"]"`
else
    CATRET=`cat - | egrep "^[^?]"`
fi

if [ -z "$CATRET" ]; then
    echo "Nothing to be updated"
else
    echo "$CATRET"
fi

exit 0

A Normal svn status

shahmir@localhost www> svn status
?         index.php
?         input/list1.a
?         input/list2.a
M        contact.php
A        default.css

Running svn status with it piped to so will return only the flags that dont have ?.

shahmir@localhost www> svn status | so
M        contact.php
A        default.css

You can also pass in a parameter to show only specific flags

shahmir@localhost www> svn status | so A
A        default.css

An empty output will return, You can change this to what you like.

shahmir@localhost www> svn status | so G
Nothing to be updated

If anyone wishes to expand on this. Please comment and i will add it here, with credits ofcourse.

P.S. use this script however whenever without legals :D

By

posted on 24th Jan 2012
© 2011 Shahmir Javaid - http://shahmirj.com/blog/21

  • All messages are moderated so will only apear after being approved


  • #subversion
  • #linux
  • #bash
  • #shell
  • #scripting
  • #svn-status
  • #filters
  • #grep

Back to Top
All content is © copyrighted, unless stated otherwise.
Subscribe, @shahmirj, Shahmir Javaid+