#!/bin/csh -f
# Edit all files in the current directory tree with names
# matching the specified patterns, defaulting to all files.

set filespecs = 
@ i = 1
foreach filespec ($*:q)
    set filespecs = ($filespecs:q -iname $filespec:q)
    if ($i < $#argv) then
        set filespecs = ($filespecs:q -or)
        @ i++
    endif
    #echo filespecs = $filespecs:q
end

if ($#argv > 0) then
    set filespecs = ( \( $filespecs:q \) )
endif

#echo filespecs = $filespecs:q
# -s not supported on Amazon Linux AMI
# find -s . $filespecs:q -print0 | xargs -0 -p e
find    . $filespecs:q -not -type d -print0 | xargs -0 -p e
        # -s      = Sort filenames within each directory so they are copied in
        #           an order that makes sense to the user.  Strictly cosmetic.
        # .       = Start in current working directory 
        # -iname  = Files matching the specified pattern (case-insensitive)
        # -not -type d = Not files that are directories
        # -print0 = Generate filenames separated by nulls not whitespace
        # xargs   = Pass filenames from find to command line of e
        # -0      = Expect filenames separated by nulls not whitespace
        # -p      = Prompt the user before executing each e command
        # -t      = Echo e commands (not needed with -p)
        # e       = Open the files with the e editor.