From: Chris Koeritz Date: Fri, 25 May 2018 20:30:47 +0000 (-0400) Subject: new scripts for acting on hierarchies X-Git-Tag: 2.140.113^2~8 X-Git-Url: https://feistymeow.org/gitweb/?p=feisty_meow.git;a=commitdiff_plain;h=a93f6fd96d2be0b9370b32566964256f8f018cec new scripts for acting on hierarchies act_on_tree runs an action on every folder that is one level down from a directory, where the default is to use the current directory. so like "act_on_tree git pull" would update all the git repositories under the current dir. there is a flag for changing the default location to act on. act_on_apps is a site-avenger specialized version of act_on_tree that runs the command on directories under ~/apps which also happen to be site avenger projects (i.e. they have an avenger5 subdirectory just under the project directory). --- diff --git a/scripts/files/act_on_tree.sh b/scripts/files/act_on_tree.sh new file mode 100644 index 00000000..86cf685d --- /dev/null +++ b/scripts/files/act_on_tree.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# act_on_tree: performs a command on a hierarchy of directories. +# +# a handy way to run a command across a set of folders. + +source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" + +#echo command line in act_on_tree is: $* + +if [ -z "$APP_NAME" ]; then + APP_NAME="$(basename $0 .sh)" +fi + +function print_instructions_and_exit() +{ + echo " +$APP_NAME [-d directory] [-f subfolder] action1 [action2...] + +This script runs an action command on each of the folders that live under the +current directory (going one level down from this directory, not recursively). +The single action command to run is built from the pieces action1, action2, +and so on that are provided on the command line. + +For example, this command: + $APP_NAME git branch +will show the branch information on each project under the current directory. + +You can specify an alternate directory to use with the '-d' flag, e.g.: + $APP_NAME -d ~/turnip_codes/ ant clean build + +You can provide a sub-folder name with -f that must exist and which the script +changes the directory to before the command is run. This supports hierarchies +where the action must take place below the children of the -d directory. + $APP_NAME -f avenger5 rgetem + +The flags and their parameters must precede the action1... arguments. + +" + exit 1 +} + +changes=true + +while [ $changes == true ]; do + changes=nope + + # check if they gave us a special directory flag. + if [ "$1" == "-d" ]; then + shift # toss the -d. + # grab the directory they want to actually use. + seekdir="$1"; shift + # check for more flags. + changes=true + fi + + # check if they gave us a subfolder name flag. + if [ "$1" == "-f" ]; then + shift # toss the -f. + # get their preferred subfolder. + subfoldername="$1"; shift + # check for more flags. + changes=true + fi +done + +# check that there are some remaining parms for the action pieces. +if [ -z "$*" ]; then + print_instructions_and_exit +fi + +# plug in our defaults. +if [ -z "$seekdir" ]; then + seekdir="." +fi +if [ -z "$subfoldername" ]; then + subfoldername="." +fi + +sep 28 + +pushd $seekdir &>/dev/null + +for i in *; do + if [ -d "$i" -a -d "$i/$subfoldername" ]; then + pushd "$i/$subfoldername" &>/dev/null + echo "[in '$i' running action: $*]" + $* + sep 28 + popd &>/dev/null + fi +done + +popd &>/dev/null + diff --git a/scripts/site_avenger/act_on_apps.sh b/scripts/site_avenger/act_on_apps.sh new file mode 100644 index 00000000..32cb32ec --- /dev/null +++ b/scripts/site_avenger/act_on_apps.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# run a command on all of the existing apps folders, but only if they appear to have site avenger projects in them. + +source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" + +# fix the app name for our call to the act_on_tree script. +export APP_NAME="$(basename $0 .sh)" + +act_on_tree -f avenger5 -d ~/apps "${@}" + +