#!/bin/bash if [[ $# < 1 ]]; then echo "Usage: $( basename $0 ) [files/dirs]" exit 1 fi function canexecute { EPATH=$(type -path $1) if [ -n "$EPATH" ] && [ -x "$EPATH" ] then return 0 else return 1 fi } function get_file_list { local fl fl="" for arg in $*; do if [[ -d $arg ]]; then dslash="${arg%/}/" sed_script="s/^/$( echo $dslash | sed 's/\//\\\//g' )/" fl="$fl $( svntr ls -R $dslash | grep '\.js$' | sed $sed_script )" elif [[ -f $arg ]]; then fl="$fl $arg" fi done fl=$( echo $fl | tr -s ' ' ) file_list=$fl } pattern=$1 shift if [[ $# < 1 && -n $TRTOP ]]; then get_file_list "$TRTOP/site/js2/" elif [[ $# < 1 ]]; then file_list="." else get_file_list "$*" fi if [[ -z $file_list || " " == $file_list ]]; then echo "No matching files" exit 0 fi if [[ -z $ACK_CMD ]]; then if canexecute ack-grep; then export ACK_CMD=ack-grep elif canexecute ack; then export ACK_CMD=ack else echo "Can't find ack-grep or ack command - please set ACK_CMD" exit 1 fi fi $ACK_CMD --js $pattern $file_list