-
-
Save pvalena/89746f18a328de2f5dad11bf4a386fe5 to your computer and use it in GitHub Desktop.
Run arbitrary commands on multiple folders or prefixed (interactive)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Run arbitrary commands on multiple folders or prefixed (interactive) | |
# | |
# ./icom [options] [command] | |
# -c clear before every command | |
# -d debug output | |
# -f [dirs] list folders (args for input for `ls -d`) | |
# | |
# Examples: | |
# Prefix every command with `oc` (openshift executable) | |
# ./icom oc | |
# | |
# Run comands in folders matching wildcard | |
# ./icom *-container | |
# | |
# Issues: | |
# [command] does not work well in combinatin with `-f` | |
# | |
myd="`pwd`" | |
C= | |
X= | |
runcx () { | |
bash -c "$C$@$X" | |
echo | |
} | |
[[ "$1" == "-c" ]] && { CLEAR="$1" ; shift ; } | |
[[ "$1" == "-d" ]] && { C="${C}set -x;" ; shift ; } | |
[[ "$1" == "-f" ]] && { shift ; FOLDERS="`bash -c "ls -d $1 | xargs readlink -e"`" ; shift ; } || FOLDERS= | |
[[ "$1" ]] && C="$C$@ " | |
while IFS="" read -r -e -d $'\n' -p ">>> $C" X; do | |
[[ "$X" ]] || break | |
history -s "$X" | |
[[ -n "$CLEAR" ]] && { clear ; echo ">>> $C$X" ; echo ; } | |
[[ -n "$FOLDERS" ]] && { | |
while read f; do | |
cd "$f" || exit 1 | |
runcx "echo -n '> ';pwd;" | |
cd "$myd" || exit 1 | |
done <<< "$FOLDERS" | |
: | |
} || { | |
runcx | |
} | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment