Skip to content

Instantly share code, notes, and snippets.

@mslinn
Created September 4, 2014 14:11
Show Gist options
  • Save mslinn/8248b0491bacf651fefd to your computer and use it in GitHub Desktop.
Save mslinn/8248b0491bacf651fefd to your computer and use it in GitHub Desktop.
Executes a command on all subdirectories one level down from the current directory. Expects to find a subdirectory of git projects
#!/bin/bash
set -eo pipefail
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
if [ -z "$2" ]; then
echo "Usage: $(basename $0) dirPattern command"
echo " Where dirPattern can be an absolute or relative path. If wildcards are used, enclose the dirPattern in single quotes"
exit -1
fi
DIRS=$(eval echo '$1')
shift
for f in $DIRS; do
if [ ! -f "$f/.ignore" ]; then
cd $f
printf "%b\n" "\n${HIGHLIGHT}$(basename $PWD)$d${NORMAL}"
$*
echo ""
cd - >/dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment