Skip to content

Instantly share code, notes, and snippets.

@frabarz
Created March 30, 2026 15:41
Show Gist options
  • Select an option

  • Save frabarz/ef23770dd085f50a32f5ca47b1b4455f to your computer and use it in GitHub Desktop.

Select an option

Save frabarz/ef23770dd085f50a32f5ca47b1b4455f to your computer and use it in GitHub Desktop.
Generates a status report for all git repositories in a folder.
#!/usr/bin/env bash
# Colores
RED=$'\e[0;31m'
GREEN=$'\e[0;32m'
YELLOW=$'\e[1;33m'
CYAN=$'\e[0;36m'
BOLD=$'\e[1m'
NC=$'\e[0m'
# Función para imprimir celdas alineadas ignorando los códigos de color
print_column() {
local text="$1"
local width="$2"
# Eliminar códigos de escape ANSI para contar la longitud real visible
local clean_text=$(echo "$text" | sed $'s/\e[[0-9;]*m//g')
local clean_len=${#clean_text}
local padding=$((width - clean_len))
printf "%s" "$text"
if [ $padding -gt 0 ]; then
printf '%*s' "$padding" ""
fi
}
# Encabezado manual para asegurar alineación con los datos
printf "${BOLD}%-25s | %-12s | %-10s | %-12s | %-10s${NC}\n" "REPOSITORIO" "ESTADO" "CAMBIOS" "BRANCHES" "STASH"
echo "------------------------------------------------------------------------------------------"
for d in */; do
dir_name="${d%/}"
[ -d "$d/.git" ] || continue
(
cd "$d" || exit
git fetch --quiet 2>/dev/null
# 1. Estado Remote
UPSTREAM='@{u}'
LOCAL=$(git rev-parse @ 2>/dev/null)
REMOTE=$(git rev-parse "$UPSTREAM" 2>/dev/null)
BASE=$(git merge-base @ "$UPSTREAM" 2>/dev/null)
if [ -z "$REMOTE" ]; then STATUS_MSG="${RED}Sin Origin${NC}"
elif [ "$LOCAL" = "$REMOTE" ]; then STATUS_MSG="${GREEN}Al día${NC}"
elif [ "$LOCAL" = "$BASE" ]; then STATUS_MSG="${YELLOW}Atrasado ↓${NC}"
elif [ "$REMOTE" = "$BASE" ]; then STATUS_MSG="${CYAN}Adelantado ↑${NC}"
else STATUS_MSG="${RED}Divergido ↕${NC}"
fi
# 2. Cambios Locales
if [ -n "$(git status --porcelain)" ]; then CHANGES_MSG="${RED}Pendientes${NC}"
else CHANGES_MSG="${GREEN}Limpio${NC}"
fi
# 3. Branches y Stash
UNTRACKED=$(git branch -vv | grep -v '\[origin/' | wc -l | tr -d ' ')
[ "$UNTRACKED" -eq "0" ] && BRANCH_MSG="0 locales" || BRANCH_MSG="${YELLOW}$UNTRACKED locales${NC}"
STASH_COUNT=$(git stash list | wc -l | tr -d ' ')
STASH_MSG="$STASH_COUNT items"
# Imprimir fila usando la función de alineación
print_column "$dir_name" 25; printf " | "
print_column "$STATUS_MSG" 12; printf " | "
print_column "$CHANGES_MSG" 10; printf " | "
print_column "$BRANCH_MSG" 12; printf " | "
print_column "$STASH_MSG" 10; printf "\n"
)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment