-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-status-tree
More file actions
executable file
·69 lines (62 loc) · 1.37 KB
/
git-status-tree
File metadata and controls
executable file
·69 lines (62 loc) · 1.37 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
#!/bin/bash
ONLYCHANGED=0
ONLYDROPBOX=0
STARTDIR="$PWD"
function usage() {
echo "Usage: $0 [-O] [-d]"
echo "Show a one-line git status summary for all git repos below the current directory"
echo "-O Only show changed (ignore untracked)"
echo "-d Only show those which have a 'dropbox' remote"
exit 1
}
parseOpts() {
while getopts "Od" opt; do
case $opt in
h) usage ;;
O) ONLYCHANGED=1 ;;
d) ONLYDROPBOX=1 ;;
*) usage ;;
esac
done
shift $(( $OPTIND - 1 ))
STARTDIR=${1:-$STARTDIR}
}
main() {
for DIR in $(find "$STARTDIR" -name .git | sort); do
pushd $(dirname "$DIR") > /dev/null
STATUS=$(git status --porcelain \
| perl -MData::Dumper -ne '
BEGIN { $c = {M=>0,T=>0,D=>0,"??"=>0}; }
$_ =~ s/^\s+|\s+$//;
($s, $fn) = split(/\s+/,$_);
$c->{$s}++;
END {
$s = 0; $s += $c->{$_} for keys %$c;
if ($s == 0) {
exit 0;
} else {
print join("|", grep {$c->{$_} != 0} (keys %$c));
exit ($c->{M} ? 2 : 1);
}
}
')
EX=$?
if [[ $EX == 1 && $ONLYCHANGED -ne 0 ]]; then
echo -e "$DIR: $STATUS"
elif [ $EX == 2 ]; then
if [[ $ONLYDROPBOX -eq 1 ]]; then
git remote | grep -q dropbox
if [ $? == 0 ]; then
echo -e "\e[31;1m$DIR: $STATUS\e[0m"
fi
else
echo -e "\e[31;1m$DIR: $STATUS\e[0m"
fi
#else
#echo "exit $EX"
fi
popd > /dev/null
done
}
parseOpts "$@"
main