98c57ed59a2d2482ce6a2ae6a96fa2c80c32f98a
[feisty_meow.git] / scripts / files / edit_files_matching.sh
1 #!/bin/bash
2
3 # finds all files that contain any one of the members of a list of patterns.
4
5 function print_instructions()
6 {
7   echo "This script requires a directory as the first parameter and then a list of"
8   echo "patterns to find within that directory.  All the files matching a pattern"
9   echo "in the list will be opened in an editor."
10
11   echo "for example:"
12
13   echo "  $(basename $0 .sh) ~/feisty_meow hoople.net hoople.org"
14   echo "the above will search the directory ~/feisty_meow for all matches to"
15   echo "the two patterns 'hoople.org' and 'hoople.net'."
16
17   exit 1
18 }
19
20 # capture the first parameter for the directory and remove it.
21 search_directory="$1"; shift
22
23 if [ -z "$search_directory" -o -z "$2" -o ! -d "$search_directory" ]; then
24   print_instructions
25 fi
26
27 function launch_editor_on_matching_files()
28 {
29   pushd "$search_directory"
30
31   local donk
32
33   # iterate over the rest of the parameters as patterns.
34   for donk in $*; do
35
36     echo "searching [$search_directory] for string [$donk]"
37     edit_list="$(bash $FEISTY_MEOW_SCRIPTS/text/search_text.sh $donk)"
38     if [ ! -z "$edit_list" ]; then
39       gvim $edit_list 2>&1 | cat 
40     fi
41
42 #np
43 #hmmm: why doesn't the np alias work?
44
45   done
46
47   popd
48 }
49
50 # invoke our function to do the real work.
51 launch_editor_on_matching_files $*
52
53 ##############
54
55 # example run for scanning feisty meow code for old domain names that are
56 # defunct:
57 # edit_files_matching $FEISTY_MEOW_APEX hoople.net hoople.org hoople.com yeticode.org yeticode.com yeticode.net cromp.com cromp.org cromp.net gruntose.net gruntose.org koeritz.net
58
59