-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitall
More file actions
executable file
·87 lines (68 loc) · 2.06 KB
/
gitall
File metadata and controls
executable file
·87 lines (68 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
type parallel >> /dev/null
if [ "$?" != "0" ]; then
echo "parallel ?"
exit 1;
fi
if [ "$1" = "--" ]; then
shift
elif [ ! -z "$1" ]; then
set -- "git" "$@"
fi
export CMD_ARGS=$*
# GITALL_RECURSIVE_DEPTH
# GITALL_CONCURRENT
# GITALL_NO_COLOR
# GITALL_TRIM_NO_OUTPUT
[ -z "$GITALL_CONCURRENT" ] && GITALL_CONCURRENT=20
[ -z "$GITALL_RECURSIVE_DEPTH" ] && GITALL_RECURSIVE_DEPTH=10
[ ! -t 1 ] && GITALL_NO_COLOR=Y
if [ ! "$GITALL_NO_COLOR" = "Y" ]; then
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_NC='\e[0m'
fi
function PrintExec() {
IDX=$(echo "$1"|cut -d\ -f1)
DIR=$(echo "$1"|cut -d\ -f2)
REPO_BASE=$(pwd)
cd "$DIR" || exit
cpwd=$(pwd)
cpwd=${cpwd:${#REPO_BASE}+1}
[ "$cpwd" = "" ] && cpwd='.'
CMD_OUTPUT=`$CMD_ARGS`
[ -z "$CMD_OUTPUT" -a "$GITALL_TRIM_NO_OUTPUT" = "y" ] && exit
REPO_CURRENT_REMOTE=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD) | cut -d'/' -f1)
printf \
"$COLOR_LIGHT_PURPLE%s$COLOR_NC $COLOR_LIGHT_BLUE%s$COLOR_NC %s $COLOR_LIGHT_BLUE%s$COLOR_NC $COLOR_YELLOW%s$COLOR_NC" \
"$IDX" \
"${cpwd}" "<=>" \
"$(git remote --verbose | grep -E "^${REPO_CURRENT_REMOTE}" | grep fetch | cut -d ' ' -f1 | cut -f2)" \
"$(git symbolic-ref --short HEAD)"
echo
[ ! -z "$CMD_OUTPUT" ] && echo -e "$CMD_OUTPUT"
}
export -f PrintExec
REPO_DIR=()
while read -r
do
[ ! -z "$REPLY" ] && REPO_DIR+=("$(dirname $REPLY)")
done << EOF
$(find . -maxdepth $GITALL_RECURSIVE_DEPTH \( -type d -or -type l \) -name ".git" | sort -u)
EOF
function loopGit() {
cnt=${#REPO_DIR[@]}
[ $cnt = 0 ] && return
for i in $(seq $cnt)
do
xi="0000000000$i"
li=${#cnt}
xi=${xi:n-li}
echo -en "$xi/${cnt} ${REPO_DIR[i - 1]}\0"
done
}
loopGit | parallel -0 --no-notice -j${GITALL_CONCURRENT} --keep-order "PrintExec {};"