From e9511529903d42718f665c69b0d4cbe33ddc4801 Mon Sep 17 00:00:00 2001 From: Brayden Traas Date: Tue, 16 Mar 2021 14:44:43 -0700 Subject: [PATCH 1/3] Added support for macOS and ZSH --- mgitstatus | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mgitstatus b/mgitstatus index d52ac72..fdde4c4 100755 --- a/mgitstatus +++ b/mgitstatus @@ -185,11 +185,21 @@ containsElement () { return 1 } +# alternative to realpath for macOS +my_realpath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + # Go through positional arguments (DIRs) or '.' if no argumnets are given for DIR in "${args[@]:-"."}"; do # We *want* to expand parameters, so disable shellcheck for this error: # shellcheck disable=SC2086 - readarray -d '' PROJ_DIRS < <(find -L "$DIR" $FIND_OPTS -depth -name ".git" -printf "%h\0" ) + + PROJ_DIRS=() + while read -r PROJ_DIR; do + PROJ_DIRS+=( "${PROJ_DIR%"/.git"}" ) # add dir removing /.git + done <<< "$(find -L "$DIR" $FIND_OPTS -depth -name ".git")" + [ $INFO_OUTPUT -eq 1 ] && \ 1>&2 echo "INFO: Examining ${#PROJ_DIRS[@]} git folders recursively..." PROJ_NEED_ATTENTION=0 @@ -206,7 +216,7 @@ for DIR in "${args[@]:-"."}"; do # This is a submodule IS_SUBMODULE="yes" BARE_DIR="$(cat "$PROJ_DIR/.git" | awk '{print $2}')" - GIT_DIR="$(realpath "$PROJ_DIR/$BARE_DIR")" + GIT_DIR="$(my_realpath "$PROJ_DIR/$BARE_DIR")" fi GIT_CONF="$GIT_DIR/config" @@ -241,7 +251,7 @@ for DIR in "${args[@]:-"."}"; do git --work-tree "$PROJ_DIR" --git-dir "$GIT_DIR" update-index -q --refresh >/dev/null 2>&1 # Now we know we are dealing with a git repo. Find out its submodules: - SUBMODULES=($(cd "$PROJ_DIR"; git config --file=.gitmodules --get-regexp ^^submodule.*\.path$ | cut -d " " -f 2)) + SUBMODULES=($(cd "$PROJ_DIR"; git config --file=.gitmodules --get-regexp "^^submodule.*\.path$" | cut -d " " -f 2)) if [[ ! -z $SUBMODULES ]]; then #printf ' | Submodule: %s\n' "${SUBMODULES[@]}" j=0 From 551fd856799fab4123cea0acca8413dd9ffa5daa Mon Sep 17 00:00:00 2001 From: Brayden Traas Date: Tue, 16 Mar 2021 14:55:58 -0700 Subject: [PATCH 2/3] minor refactor to re-include shellcheck ignore --- mgitstatus | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mgitstatus b/mgitstatus index fdde4c4..825a74e 100755 --- a/mgitstatus +++ b/mgitstatus @@ -194,11 +194,13 @@ my_realpath() { for DIR in "${args[@]:-"."}"; do # We *want* to expand parameters, so disable shellcheck for this error: # shellcheck disable=SC2086 + INITIAL_DIRS_LINES=$(find -L "$DIR" $FIND_OPTS -depth -name ".git") + # Expand lines of string into an array PROJ_DIRS=() while read -r PROJ_DIR; do PROJ_DIRS+=( "${PROJ_DIR%"/.git"}" ) # add dir removing /.git - done <<< "$(find -L "$DIR" $FIND_OPTS -depth -name ".git")" + done <<< "$(echo -e "$INITIAL_DIRS_LINES")" [ $INFO_OUTPUT -eq 1 ] && \ 1>&2 echo "INFO: Examining ${#PROJ_DIRS[@]} git folders recursively..." From de2a3c18ba380ed9320cac79ca1cb529d9de3afb Mon Sep 17 00:00:00 2001 From: Brayden Traas Date: Tue, 16 Mar 2021 16:09:48 -0700 Subject: [PATCH 3/3] now sorting locale-independent for tests, removed added whitespace by wc on mac --- mgitstatus | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mgitstatus b/mgitstatus index 825a74e..c5b36f0 100755 --- a/mgitstatus +++ b/mgitstatus @@ -194,7 +194,7 @@ my_realpath() { for DIR in "${args[@]:-"."}"; do # We *want* to expand parameters, so disable shellcheck for this error: # shellcheck disable=SC2086 - INITIAL_DIRS_LINES=$(find -L "$DIR" $FIND_OPTS -depth -name ".git") + INITIAL_DIRS_LINES=$(find -L "$DIR" $FIND_OPTS -depth -name ".git" | LC_ALL=C sort -n) # Expand lines of string into an array PROJ_DIRS=() @@ -367,7 +367,7 @@ for DIR in "${args[@]:-"."}"; do if [ "$STASHES" -ne 0 ] && [ "$NO_STASHES" -eq 0 ]; then STATUS_NEEDS="${STATUS_NEEDS}${C_STASHES}$STASHES stashes${C_RESET} " fi - STALLED_COUNT=$(echo $STALLED | tr ',' ' ' | wc -w) + STALLED_COUNT=$(echo $STALLED | tr ',' ' ' | wc -w | xargs) if [ "$STALLED_COUNT" -ne 0 ] && [[ "$BNAME" != "HEAD" ]] && [ -z "$NO_STALLED" ]; then STATUS_NEEDS="${STATUS_NEEDS}${C_STALLED}${STALLED_COUNT} stalled ($STALLED)${C_RESET} " ## dump the commit logs which only the other branches have