Skip to content

Instantly share code, notes, and snippets.

@xgvargas
Last active April 4, 2023 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgvargas/68f13e96f6db782bd064ba69a817ddde to your computer and use it in GitHub Desktop.
Save xgvargas/68f13e96f6db782bd064ba69a817ddde to your computer and use it in GitHub Desktop.
List GIT status of all sub directories
#! /usr/bin/bash
if [ -t 1 ]; then
# executed in terminal
GREY='\e[1;30m'
RED='\e[1;31m'
GREEN='\e[1;32m'
YELLOW='\e[1;33m'
BLUE='\e[1;34m'
MARGENTA='\e[1;35m'
CYAN='\e[1;36m'
WHITE='\e[1;37m'
NONE='\e[0m'
fi
basic_info_f() {
local name="$1"
if [[ -d $name/.git ]]; then
cd $name
stat=""
[ ! -z "$(git status --porcelain)" ] && stat="$stat${RED}Dirty "
[ ! -z "$(git cherry 2>&1)" ] && stat="$stat${BLUE}Non pushed "
[ -z "$stat" ] && stat="${GREEN}Clean"
cd - >> /dev/null
else
stat="${YELLOW}Not GIT"
fi
printf "%-30s %b${NONE}\n" "$name" "$stat"
}
find -maxdepth 1 -mindepth 1 -type d | sort | while read dir; do
basic_info_f "$dir";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment