Skip to content

Commit 797e221

Browse files
committed
Implemented --flatten option: show only one status per line
1 parent 2021aee commit 797e221

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ for that repo to `true`. (See "usage" below for an example).
3333

3434
# Usage
3535

36-
Usage: ./mgitstatus [--version] [-w] [-e] [-f] [--no-X] [-d/--depth=2] [DIR [DIR]...]
36+
Usage: mgitstatus [--version] [-w] [-e] [-f] [--throttle SEC] [-c] [-d/--depth=2] [--flatten] [--no-X] [DIR [DIR]...]
3737

3838
mgitstatus shows uncommitted, untracked and unpushed changes in multiple Git
3939
repositories. By default, mgitstatus scans two directories deep. This can be
4040
changed with the -d (--depth) option. If DEPTH is 0, the scan is infinitely
4141
deep.
4242

43-
--version Show version
44-
-w Warn about dirs that are not Git repositories
45-
-e Exclude repos that are 'ok'
46-
-f Do a 'git fetch' on each repo (slow for many repos)
47-
-c Force color output (preserve colors when using pipes)
48-
-d, --depth=2 Scan this many directories deep
43+
--version Show version
44+
-w Warn about dirs that are not Git repositories
45+
-e Exclude repos that are 'ok'
46+
-f Do a 'git fetch' on each repo (slow for many repos)
47+
--throttle SEC Wait SEC seconds between each 'git fetch' (-f option)
48+
-c Force color output (preserve colors when using pipes)
49+
-d, --depth=2 Scan this many directories deep
50+
--flatten Show only one status per line
4951

5052
You can limit output with the following options:
5153

mgitstatus

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DEBUG=0
88
usage () {
99
cat << EOF >&2
1010
11-
Usage: $0 [--version] [-w] [-e] [-f] [--throttle SEC] [--no-X] [-d/--depth=2] [DIR [DIR]...]
11+
Usage: $0 [--version] [-w] [-e] [-f] [--throttle SEC] [-c] [-d/--depth=2] [--flatten] [--no-X] [DIR [DIR]...]
1212
1313
mgitstatus shows uncommitted, untracked and unpushed changes in multiple Git
1414
repositories. By default, mgitstatus scans two directories deep. This can be
@@ -22,6 +22,7 @@ deep.
2222
--throttle SEC Wait SEC seconds between each 'git fetch' (-f option)
2323
-c Force color output (preserve colors when using pipes)
2424
-d, --depth=2 Scan this many directories deep
25+
--flatten Show only one status per line
2526
2627
You can limit output with the following options:
2728
@@ -40,6 +41,7 @@ WARN_NOT_REPO=0
4041
EXCLUDE_OK=0
4142
DO_FETCH=0
4243
FORCE_COLOR=0
44+
FLATTEN=0
4345
NO_PUSH=0
4446
NO_PULL=0
4547
NO_UPSTREAM=0
@@ -73,6 +75,9 @@ while [ -n "$1" ]; do
7375
if [ "$1" = "-c" ]; then
7476
FORCE_COLOR=1
7577
fi
78+
if [ "$1" = "--flatten" ]; then
79+
FLATTEN=1
80+
fi
7681
if [ "$1" = "--no-push" ]; then
7782
NO_PUSH=1
7883
fi
@@ -253,35 +258,52 @@ for DIR in "${@:-"."}"; do
253258
STASHES=$(git stash list | wc -l)
254259
cd "$OLDPWD" || exit
255260

256-
# Build up the status string
261+
# Build up the status string if not flattening. Otherwise, print
262+
# results immediately.
257263
IS_OK=0 # 0 = Repo needs something, 1 = Repo needs nothing ('ok')
258264
STATUS_NEEDS=""
259265
if [ -n "$NEEDS_PUSH_BRANCHES" ] && [ "$NO_PUSH" -eq 0 ]; then
260-
STATUS_NEEDS="${STATUS_NEEDS}${C_NEEDS_PUSH}Needs push ($NEEDS_PUSH_BRANCHES)${C_RESET} "
266+
THIS_STATUS="${C_NEEDS_PUSH}Needs push ($NEEDS_PUSH_BRANCHES)${C_RESET}"
267+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
268+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
261269
fi
262270
if [ -n "$NEEDS_PULL_BRANCHES" ] && [ "$NO_PULL" -eq 0 ]; then
263-
STATUS_NEEDS="${STATUS_NEEDS}${C_NEEDS_PULL}Needs pull ($NEEDS_PULL_BRANCHES)${C_RESET} "
271+
THIS_STATUS="${C_NEEDS_PULL}Needs pull ($NEEDS_PULL_BRANCHES)${C_RESET}"
272+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
273+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
264274
fi
265275
if [ -n "$NEEDS_UPSTREAM_BRANCHES" ] && [ "$NO_UPSTREAM" -eq 0 ]; then
266-
STATUS_NEEDS="${STATUS_NEEDS}${C_NEEDS_UPSTREAM}Needs upstream ($NEEDS_UPSTREAM_BRANCHES)${C_RESET} "
276+
THIS_STATUS="${C_NEEDS_UPSTREAM}Needs upstream ($NEEDS_UPSTREAM_BRANCHES)${C_RESET}"
277+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
278+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
267279
fi
268280
if [ "$UNSTAGED" -ne 0 ] || [ "$UNCOMMITTED" -ne 0 ] && [ "$NO_UNCOMMITTED" -eq 0 ]; then
269-
STATUS_NEEDS="${STATUS_NEEDS}${C_NEEDS_COMMIT}Uncommitted changes${C_RESET} "
281+
THIS_STATUS="${C_NEEDS_COMMIT}Uncommitted changes${C_RESET}"
282+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
283+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
270284
fi
271285
if [ "$UNTRACKED" != "" ] && [ "$NO_UNTRACKED" -eq 0 ]; then
272-
STATUS_NEEDS="${STATUS_NEEDS}${C_UNTRACKED}Untracked files${C_RESET} "
286+
THIS_STATUS="${C_UNTRACKED}Untracked files${C_RESET}"
287+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
288+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
273289
fi
274290
if [ "$STASHES" -ne 0 ] && [ "$NO_STASHES" -eq 0 ]; then
275-
STATUS_NEEDS="${STATUS_NEEDS}${C_STASHES}$STASHES stashes${C_RESET} "
291+
THIS_STATUS="${C_STASHES}$STASHES stashes${C_RESET}"
292+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
293+
[ "$FLATTEN" -eq 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
276294
fi
277295
if [ "$STATUS_NEEDS" = "" ]; then
278296
IS_OK=1
279-
STATUS_NEEDS="${STATUS_NEEDS}${C_OK}ok${C_RESET} "
297+
THIS_STATUS="${C_OK}ok${C_RESET}"
298+
STATUS_NEEDS="${STATUS_NEEDS}${THIS_STATUS} "
299+
[ "$FLATTEN" -eq 1 ] && [ "$EXCLUDE_OK" -ne 1 ] && printf "${PROJ_DIR}: $THIS_STATUS\n"
280300
fi
281301

282-
# Print the output, unless repo is 'ok' and -e was specified
283-
if [ "$IS_OK" -ne 1 ] || [ "$EXCLUDE_OK" -ne 1 ]; then
284-
printf "${PROJ_DIR}: $STATUS_NEEDS\n"
302+
if [ "$FLATTEN" -ne 1 ]; then
303+
# Print the output, unless repo is 'ok' and -e was specified
304+
if [ "$IS_OK" -ne 1 ] || [ "$EXCLUDE_OK" -ne 1 ]; then
305+
printf "${PROJ_DIR}: $STATUS_NEEDS\n"
306+
fi
285307
fi
286308

287309
# Throttle if requested

mgitstatus.1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ multiple Git repos.
1010
.PP
1111
\f[B]mgitstatus\f[R] [\f[B]\-\-version\f[R]] [\f[B]\-w\f[R]]
1212
[\f[B]\-e\f[R]] [\f[B]\-f\f[R]] [\f[B]\-\-throttle\f[R] SEC]
13-
[\f[B]\-\-no\-X\f[R]] [\f[B]\-d/\-\-depth\f[R]=2] [\f[B]DIR\f[R]
14-
[\f[B]DIR\f[R]]\&...]
13+
[\f[B]\-c\f[R]] [\f[B]\-d/\-\-depth\f[R]=2] [\f[B]\-\-flatten\f[R]]
14+
[\f[B]\-\-no\-X\f[R]] [\f[B]DIR\f[R] [\f[B]DIR\f[R]]\&...]
1515
.SH DESCRIPTION
1616
.PP
1717
\f[B]mgitstatus\f[R] shows uncommitted, untracked and unpushed changes
@@ -70,6 +70,11 @@ Force color output (preserve colors when using pipes)
7070
Scan this many directories deep.
7171
Default is 2.
7272
If \f[B]0\f[R], the scan is infinitely deep
73+
.TP
74+
.B \f[B]\-\-flatten\f[R]
75+
Flatten output by only showing one status per line.
76+
If a repo has multiple statuses, multiple lines are shown for that repo.
77+
This aids in grepability.
7378
.PP
7479
You can limit output with the following options:
7580
.TP

mgitstatus.1.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mgitstatus - Show uncommitted, untracked and unpushed changes for multiple Git r
88

99
# SYNOPSIS
1010

11-
**mgitstatus** [**\--version**] [**-w**] [**-e**] [**-f**] [**\--throttle** SEC] [**\--no-X**] [**-d/\--depth**=2] [**DIR** [**DIR**]...]
11+
**mgitstatus** [**\--version**] [**-w**] [**-e**] [**-f**] [**\--throttle** SEC] [**\-c**] [**-d/\--depth**=2] [**\--flatten**] [**\--no-X**] [**DIR** [**DIR**]...]
1212

1313
# DESCRIPTION
1414

@@ -64,6 +64,9 @@ mgitstatus makes no guarantees that all states are taken into account.
6464
**-d, \--depth=2**
6565
: Scan this many directories deep. Default is 2. If **0**, the scan is infinitely deep
6666

67+
**\--flatten**
68+
: Flatten output by only showing one status per line. If a repo has multiple statuses, multiple lines are shown for that repo. This aids in grepability.
69+
6770
You can limit output with the following options:
6871

6972
**\--no-push**

0 commit comments

Comments
 (0)