Last active
February 2, 2024 13:43
-
-
Save SPodjasek/785837ba77a38a5f72e4e39f51c05172 to your computer and use it in GitHub Desktop.
Show status of git repositories found in subdirectories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
function check_git_status() { | |
local DARK_GRAY="\x1B[0;30m" | |
local GRAY="\x1B[1;30m" | |
local LIGHT_GRAY="\x1B[0;37m" | |
local RED="\x1B[1;31m" | |
local NO_COLOUR="\x1B[0m" | |
# This is used to shift every command output to the right | |
prefixoutput () { | |
echo "$3" | sed -r "s/.*/$GRAY$1 $2&$NO_COLOUR/" | |
} | |
local dir="$1" | |
pushd "$dir" >/dev/null || return | |
if [ -d ".git" ]; then | |
local STASH="$(git stash list)" | |
local STATUS="$(git status --porcelain)" | |
local AHEAD="$(git log --oneline --branches --not --remotes)" | |
if [ -n "$STATUS" ] || [ -n "$AHEAD" ] || [ -n "$STASH" ]; then | |
echo -e "📁 \e[1;34m$dir\e[0m" | |
if [ -n "$STASH" ]; then | |
echo -e " \e[1;31mstashed changes\e[0m" | |
fi | |
if [ -n "$STATUS" ]; then | |
echo -e " \e[1;32muncommitted changes:\e[0m" | |
prefixoutput " > " "\x1B[0;32m" "$STATUS" | |
fi | |
if [ -n "$AHEAD" ]; then | |
echo -e " \e[1;33mnot pushed changes:\e[0m" | |
prefixoutput " > " "\x1B[0;33m" "$AHEAD" | |
fi | |
fi | |
fi | |
popd >/dev/null || return | |
} | |
export -f check_git_status | |
find . -type d -name ".git" $@ -exec bash -c 'check_git_status "${0%/.git}"' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment