#!/bin/bash # svngrep - recursive grep safe for SVN trees (and quilt) # Copyright (C) 2008 Daniel Jacobowitz # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . args=() files=() next_opt=false next_file=false need_pattern=true for arg; do if $next_file; then if $need_pattern; then args=("${args[@]}" "$arg") need_pattern=false else files=("${files[@]}" "$arg") fi elif $next_opt; then next_opt=false args=("${args[@]}" "$arg") else case "$arg" in -e|-f) need_pattern=false next_opt=true args=("${args[@]}" "$arg") ;; -m|-A|-B|-C|-D|-d) next_opt=true args=("${args[@]}" "$arg") ;; -r) # Just consume -r. ;; --) args=("${args[@]}" "$arg") next_file=true ;; -*) args=("${args[@]}" "$arg") ;; *) if $need_pattern; then args=("${args[@]}" "$arg") need_pattern=false else files=("${files[@]}" "$arg") fi next_file=true ;; esac fi done find "${files[@]}" -name .svn -prune \ -o -name .pc -prune -o -name \*~ -prune \ -o -type f -print0 | xargs -0 grep "${args[@]}"