Created
April 14, 2015 06:09
-
-
Save uasi/28415c76416986e81030 to your computer and use it in GitHub Desktop.
ghq で管理している各リポジトリでコマンドを実行する ghq-foreach 書いた ref: http://qiita.com/uasi/items/610ef5745fc35745fd54
This file contains 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 | |
# | |
# ghq-foreach - executes git subcmd or shell cmd for each repo managed by ghq | |
# | |
EXEC= | |
QUIET= | |
say() { | |
[[ -n "$QUIET" ]] && return | |
if [[ -t 1 ]]; then | |
printf '\e[1;34m%s\e[m\n' "$1" | |
else | |
printf '%s\n' "$1" | |
fi | |
} | |
main() { | |
if [[ "$1" = "-q" ]]; then | |
QUIET=1 | |
shift | |
fi | |
if [[ "$1" = "-e" ]]; then | |
EXEC=1 | |
shift | |
fi | |
if [[ "$#" -eq 0 ]]; then | |
echo "usage: ghq-foreach [-q] (<git-cmd> | -e <shell-cmd>) [args...]" >&2 | |
echo " -e Execute shell command" >&2 | |
echo " -q Don't print each repository path" >&2 | |
return 1 | |
fi | |
ghq list -p | while read -r repo; do | |
( | |
cd "$repo" | |
say "> $repo" | |
if [[ -n "$EXEC" ]]; then | |
"$@" | |
else | |
git "$@" | |
fi | |
) | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment