88usage () {
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
1313mgitstatus shows uncommitted, untracked and unpushed changes in multiple Git
1414repositories. By default, mgitstatus scans two directories deep. This can be
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
2627You can limit output with the following options:
2728
@@ -40,6 +41,7 @@ WARN_NOT_REPO=0
4041EXCLUDE_OK=0
4142DO_FETCH=0
4243FORCE_COLOR=0
44+ FLATTEN=0
4345NO_PUSH=0
4446NO_PULL=0
4547NO_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
0 commit comments