3 # act_on_tree: performs a command on a hierarchy of directories.
5 # a handy way to run a command across a set of folders.
7 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
9 #echo command line in act_on_tree is: $*
11 if [ -z "$APP_NAME" ]; then
12 APP_NAME="$(basename $0 .sh)"
15 function print_instructions_and_exit()
18 $APP_NAME [-d directory] [-f subfolder] action1 [action2...]
20 This script runs an action command on each of the folders that live under the
21 current directory (going one level down from this directory, not recursively).
22 The single action command to run is built from the pieces action1, action2,
23 and so on that are provided on the command line.
25 For example, this command:
27 will show the branch information on each project under the current directory.
29 You can specify an alternate directory to use with the '-d' flag, e.g.:
30 $APP_NAME -d ~/turnip_codes/ ant clean build
32 You can provide a sub-folder name with -f that must exist and which the script
33 changes the directory to before the command is run. This supports hierarchies
34 where the action must take place below the children of the -d directory.
35 $APP_NAME -f avenger5 rgetem
37 The flags and their parameters must precede the action1... arguments.
45 while [ $changes == true ]; do
48 # check if they gave us a special directory flag.
49 if [ "$1" == "-d" ]; then
51 # grab the directory they want to actually use.
53 # check for more flags.
57 # check if they gave us a subfolder name flag.
58 if [ "$1" == "-f" ]; then
60 # get their preferred subfolder.
61 subfoldername="$1"; shift
62 # check for more flags.
67 # check that there are some remaining parms for the action pieces.
69 print_instructions_and_exit
72 # plug in our defaults.
73 if [ -z "$seekdir" ]; then
76 if [ -z "$subfoldername" ]; then
82 pushd $seekdir &>/dev/null
85 if [ -d "$i" -a -d "$i/$subfoldername" ]; then
86 pushd "$i/$subfoldername" &>/dev/null
87 echo "[in '$i' running action: $*]"