From ea00105ee819328ffa91f86f7a04f90801d12094 Mon Sep 17 00:00:00 2001 From: Vilius Puidokas Date: Mon, 16 Mar 2020 10:22:40 -0400 Subject: [PATCH 1/2] mgitstatus -b shall print current branch unless master --- mgitstatus | 15 ++++++++++++++- mgitstatus.1 | 9 ++++++++- mgitstatus.1.md | 5 +++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mgitstatus b/mgitstatus index 9330e36..40cf0a1 100755 --- a/mgitstatus +++ b/mgitstatus @@ -20,6 +20,7 @@ deep. -e Exclude repos that are 'ok' -f Do a 'git fetch' on each repo (slow for many repos) -c Force color output (preserve colors when using pipes) + -b Show current branch -d, --depth=2 Scan this many directories deep You can limit output with the following options: @@ -45,6 +46,7 @@ NO_UPSTREAM=0 NO_UNCOMMITTED=0 NO_UNTRACKED=0 NO_STASHES=0 +DO_STATUS=0 DEPTH=2 while [ -n "$1" ]; do @@ -71,6 +73,9 @@ while [ -n "$1" ]; do if [ "$1" = "-c" ]; then FORCE_COLOR=1 fi + if [ "$1" = "-b" ]; then + DO_STATUS=1 + fi if [ "$1" = "--no-push" ]; then NO_PUSH=1 fi @@ -239,9 +244,15 @@ for DIR in "${@:-"."}"; do STASHES=$(git stash list | wc -l) cd "$OLDPWD" || exit + CURRENT_BRANCH=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" branch --show-current) + # Build up the status string IS_OK=0 # 0 = Repo needs something, 1 = Repo needs nothing ('ok') STATUS_NEEDS="" + BRANCH_PRINT="" + if [ -n "$CURRENT_BRANCH" ] && [ "$CURRENT_BRANCH" != "master" ] && [ "$DO_STATUS" -eq 1 ]; then + BRANCH_PRINT="[${C_OK}${CURRENT_BRANCH}${C_RESET}] " + fi if [ -n "$NEEDS_PUSH_BRANCHES" ] && [ "$NO_PUSH" -eq 0 ]; then STATUS_NEEDS="${STATUS_NEEDS}${C_NEEDS_PUSH}Needs push ($NEEDS_PUSH_BRANCHES)${C_RESET} " fi @@ -262,7 +273,9 @@ for DIR in "${@:-"."}"; do fi if [ "$STATUS_NEEDS" = "" ]; then IS_OK=1 - STATUS_NEEDS="${STATUS_NEEDS}${C_OK}ok${C_RESET} " + STATUS_NEEDS="${BRANCH_PRINT}${STATUS_NEEDS}${C_OK}ok${C_RESET} " + else + STATUS_NEEDS="${BRANCH_PRINT}${STATUS_NEEDS}" fi # Print the output, unless repo is 'ok' and -e was specified diff --git a/mgitstatus.1 b/mgitstatus.1 index a4cfec2..f6c78fb 100644 --- a/mgitstatus.1 +++ b/mgitstatus.1 @@ -8,7 +8,7 @@ mgitstatus \[en] Show uncommitted, untracked and unpushed changes for multiple Git repos. .SH SYNOPSIS .PP -\f[B]mgitstatus\f[] [\f[B]\-\-version\f[]] [\f[B]\-w\f[]] [\f[B]\-e\f[]] +\f[B]mgitstatus\f[] [\f[B]\-\-version\f[]] [\f[B]\-b\f[]] [\f[B]\-w\f[]] [\f[B]\-e\f[]] [\f[B]\-f\f[]] [\f[B]\-\-no\-X\f[]] [\f[B]\-d/\-\-depth\f[]=2] [\f[B]DIR\f[] [\f[B]DIR\f[]]...] .SH DESCRIPTION @@ -21,6 +21,8 @@ If \f[B]DEPTH\f[] is 0, the scan is infinitely deep. .PP mgitstatus shows: .IP \[bu] 2 +\f[B]Current branch\f[] if the option -b is given. +.IP \[bu] 2 \f[B]Uncommitted changes\f[] if there are unstaged or uncommitted changes on the checked out branch. .IP \[bu] 2 @@ -52,6 +54,11 @@ Show version .RS .RE .TP +.B \f[B]\-b\f[] +Print current branch (master is skipped) +.RS +.RE +.TP .B \f[B]\-w\f[] Warn about dirs that are not Git repositories .RS diff --git a/mgitstatus.1.md b/mgitstatus.1.md index d9f0f8c..76ef6c1 100644 --- a/mgitstatus.1.md +++ b/mgitstatus.1.md @@ -19,6 +19,8 @@ is infinitely deep. mgitstatus shows: +- **Current branch** if the -b option is given. Skips 'master' branch. + - **Uncommitted changes** if there are unstaged or uncommitted changes on the checked out branch. @@ -46,6 +48,9 @@ mgitstatus makes no guarantees that all states are taken into account. **--version** : Show version +**-b** +: Print current branch + **-w** : Warn about dirs that are not Git repositories From 641815ac8f01c4748d5132e847ab7c0781d2cd6b Mon Sep 17 00:00:00 2001 From: Vilius Puidokas Date: Mon, 16 Mar 2020 12:00:41 -0400 Subject: [PATCH 2/2] usage fix --- mgitstatus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mgitstatus b/mgitstatus index 40cf0a1..684c4db 100755 --- a/mgitstatus +++ b/mgitstatus @@ -8,7 +8,7 @@ DEBUG=0 usage () { cat << EOF >&2 -Usage: $0 [--version] [-w] [-e] [-f] [--no-X] [-d/--depth=2] [DIR [DIR]...] +Usage: $0 [--version] [-b] [-w] [-e] [-f] [--no-X] [-d/--depth=2] [DIR [DIR]...] mgitstatus shows uncommited, untracked and unpushed changes in multiple Git repositories. By default, mgitstatus scans two directories deep. This can be