Add git-check-all.sh, git-update-all.sh und .p10k.zsh
- bin/git-check-all.sh: Status aller Git-Repos prüfen (alias gitcheck) - bin/git-update-all.sh: Alle Git-Repos pullen (alias gitupdate) - .p10k.zsh: Powerlevel10k-Konfiguration für einheitliches Terminal-Setup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4769086d28
commit
9df9d134a3
3 changed files with 2003 additions and 0 deletions
159
bin/git-check-all.sh
Executable file
159
bin/git-check-all.sh
Executable file
|
|
@ -0,0 +1,159 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Default-Basisverzeichnis
|
||||
BASE_DIR="$HOME/git-projekte"
|
||||
SHOW_ALL=false
|
||||
SHORT_MODE=false
|
||||
|
||||
# --- Farben ------------------------------------------------------------
|
||||
if [ -t 1 ]; then
|
||||
C_RED=$'\033[31m'
|
||||
C_GREEN=$'\033[32m'
|
||||
C_YELLOW=$'\033[33m'
|
||||
C_CYAN=$'\033[36m'
|
||||
C_BOLD=$'\033[1m'
|
||||
C_RESET=$'\033[0m'
|
||||
else
|
||||
C_RED=""; C_GREEN=""; C_YELLOW=""; C_CYAN=""; C_BOLD=""; C_RESET=""
|
||||
fi
|
||||
|
||||
# --- Argumente parsen --------------------------------------------------
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-a|--all)
|
||||
SHOW_ALL=true
|
||||
shift
|
||||
;;
|
||||
-s|--short)
|
||||
SHORT_MODE=true
|
||||
shift
|
||||
;;
|
||||
-p|--path)
|
||||
BASE_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
cat <<EOF
|
||||
Usage: ${0##*/} [OPTIONEN]
|
||||
|
||||
Optionen:
|
||||
-a, --all alle Repositories anzeigen (auch saubere)
|
||||
-s, --short kompakte Ausgabe (eine Zeile pro Repo)
|
||||
-p, --path DIR anderes Basisverzeichnis statt ~/git-projekte
|
||||
-h, --help diese Hilfe anzeigen
|
||||
|
||||
Standard-Basisverzeichnis: $HOME/git-projekte
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unbekannte Option: $1" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# --- Checks ------------------------------------------------------------
|
||||
if [ ! -d "$BASE_DIR" ]; then
|
||||
echo "Verzeichnis $BASE_DIR existiert nicht – nichts zu prüfen."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Suche Git-Repositories unter: $BASE_DIR"
|
||||
echo
|
||||
|
||||
find_git_dirs() {
|
||||
find "$BASE_DIR" -type d -name ".git" -print 2>/dev/null
|
||||
}
|
||||
|
||||
# --- .git-Verzeichnisse einsammeln & sortieren ------------------------
|
||||
gitdirs=()
|
||||
while IFS= read -r gitdir; do
|
||||
gitdirs+=( "$gitdir" )
|
||||
done < <(find_git_dirs)
|
||||
|
||||
if [ ${#gitdirs[@]} -eq 0 ]; then
|
||||
echo "Keine Git-Repositories gefunden."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
IFS=$'\n' sorted_gitdirs=( $(printf '%s\n' "${gitdirs[@]}" | sort) )
|
||||
unset IFS
|
||||
|
||||
# --- Auswertung --------------------------------------------------------
|
||||
total=0
|
||||
dirty=0
|
||||
clean=0
|
||||
|
||||
for gitdir in "${sorted_gitdirs[@]}"; do
|
||||
repo_dir="${gitdir%/.git}"
|
||||
((total++))
|
||||
|
||||
cd "$repo_dir" || continue
|
||||
|
||||
# Lokale, nicht committete Änderungen?
|
||||
status_output="$(git status --porcelain 2>/dev/null || echo "")"
|
||||
has_local_changes=false
|
||||
if [[ -n "$status_output" ]]; then
|
||||
has_local_changes=true
|
||||
fi
|
||||
|
||||
# Commits vor/nach Upstream?
|
||||
ahead=0
|
||||
behind=0
|
||||
if upstream_info=$(git rev-list --left-right --count "@{u}...HEAD" 2>/dev/null); then
|
||||
read -r behind ahead <<<"$upstream_info"
|
||||
fi
|
||||
|
||||
is_dirty=false
|
||||
$has_local_changes && is_dirty=true
|
||||
((ahead > 0)) && is_dirty=true
|
||||
((behind > 0)) && is_dirty=true
|
||||
|
||||
if $is_dirty; then
|
||||
((dirty++))
|
||||
else
|
||||
((clean++))
|
||||
$SHOW_ALL || continue
|
||||
fi
|
||||
|
||||
# Zusammenfassungstext bauen
|
||||
summary=""
|
||||
$has_local_changes && summary+="lokale Änderungen; "
|
||||
((ahead > 0)) && summary+="$ahead nicht gepushte Commits; "
|
||||
((behind > 0)) && summary+="$behind nicht gepullte Commits; "
|
||||
summary="${summary%; }"
|
||||
[ -z "$summary" ] && summary="clean"
|
||||
|
||||
if $SHORT_MODE; then
|
||||
# eine Zeile pro Repo
|
||||
if $is_dirty; then
|
||||
printf "%sDIRTY%s %s - %s\n" "$C_RED" "$C_RESET" "$repo_dir" "$summary"
|
||||
else
|
||||
printf "%sCLEAN%s %s - %s\n" "$C_GREEN" "$C_RESET" "$repo_dir" "$summary"
|
||||
fi
|
||||
else
|
||||
# detailliertere Ausgabe
|
||||
if $is_dirty; then
|
||||
printf "%s▸ %s%s\n" "$C_RED" "$repo_dir" "$C_RESET"
|
||||
else
|
||||
printf "%s▸ %s%s\n" "$C_GREEN" "$repo_dir" "$C_RESET"
|
||||
fi
|
||||
printf " %s%s%s\n\n" "$C_CYAN" "$summary" "$C_RESET"
|
||||
fi
|
||||
done
|
||||
|
||||
# --- Zusammenfassung ---------------------------------------------------
|
||||
echo "${C_BOLD}Gesamt:${C_RESET} $total Repositories"
|
||||
echo "${C_GREEN}Clean:${C_RESET} $clean"
|
||||
echo "${C_RED}Dirty:${C_RESET} $dirty"
|
||||
echo
|
||||
|
||||
if ((dirty == 0)); then
|
||||
echo "Alle gefundenen Git-Repositories in $BASE_DIR sind sauber. ✅"
|
||||
exit 0
|
||||
else
|
||||
echo "$dirty Repository(s) mit offenen Änderungen. ⚠️"
|
||||
exit 1
|
||||
fi
|
||||
106
bin/git-update-all.sh
Executable file
106
bin/git-update-all.sh
Executable file
|
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_DIR="$HOME/git-projekte"
|
||||
|
||||
# --- Farben ------------------------------------------------------------
|
||||
if [ -t 1 ]; then
|
||||
C_RED=$'\033[31m'
|
||||
C_GREEN=$'\033[32m'
|
||||
C_YELLOW=$'\033[33m'
|
||||
C_BOLD=$'\033[1m'
|
||||
C_RESET=$'\033[0m'
|
||||
else
|
||||
C_RED=""; C_GREEN=""; C_YELLOW=""; C_BOLD=""; C_RESET=""
|
||||
fi
|
||||
|
||||
# --- Argumente ----------------------------------------------------------
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-p|--path) BASE_DIR="$2"; shift 2 ;;
|
||||
-h|--help)
|
||||
cat <<EOF
|
||||
Usage: ${0##*/} [OPTIONEN]
|
||||
|
||||
Synchronisiert alle Git-Repositories (git pull).
|
||||
Repos mit lokalen Aenderungen werden uebersprungen.
|
||||
|
||||
Optionen:
|
||||
-p, --path DIR anderes Basisverzeichnis statt ~/git-projekte
|
||||
-h, --help diese Hilfe anzeigen
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*) echo "Unbekannte Option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -d "$BASE_DIR" ]; then
|
||||
echo "Verzeichnis $BASE_DIR existiert nicht."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "${C_BOLD}Git-Repositories aktualisieren: $BASE_DIR${C_RESET}"
|
||||
echo
|
||||
|
||||
# --- Repos finden und sortieren -----------------------------------------
|
||||
gitdirs=()
|
||||
while IFS= read -r gitdir; do
|
||||
gitdirs+=( "$gitdir" )
|
||||
done < <(find "$BASE_DIR" -type d -name ".git" -print 2>/dev/null)
|
||||
|
||||
if [ ${#gitdirs[@]} -eq 0 ]; then
|
||||
echo "Keine Git-Repositories gefunden."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
IFS=$'\n' sorted_gitdirs=( $(printf '%s\n' "${gitdirs[@]}" | sort) )
|
||||
unset IFS
|
||||
|
||||
# --- Pull ---------------------------------------------------------------
|
||||
total=0
|
||||
updated=0
|
||||
skipped=0
|
||||
failed=0
|
||||
|
||||
for gitdir in "${sorted_gitdirs[@]}"; do
|
||||
repo_dir="${gitdir%/.git}"
|
||||
repo_name="${repo_dir#$BASE_DIR/}"
|
||||
((total++))
|
||||
|
||||
cd "$repo_dir" || continue
|
||||
|
||||
# Lokale Aenderungen? -> ueberspringen
|
||||
if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
|
||||
printf "${C_YELLOW}SKIP${C_RESET} %s (lokale Aenderungen)\n" "$repo_name"
|
||||
((skipped++))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Kein Remote? -> ueberspringen
|
||||
if ! git remote | grep -q .; then
|
||||
printf "${C_YELLOW}SKIP${C_RESET} %s (kein Remote)\n" "$repo_name"
|
||||
((skipped++))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Pull
|
||||
if output=$(git pull --ff-only 2>&1); then
|
||||
if echo "$output" | grep -q "Already up to date"; then
|
||||
printf "${C_GREEN}OK${C_RESET} %s (aktuell)\n" "$repo_name"
|
||||
else
|
||||
printf "${C_GREEN}PULL${C_RESET} %s (aktualisiert)\n" "$repo_name"
|
||||
((updated++))
|
||||
fi
|
||||
else
|
||||
printf "${C_RED}FAIL${C_RESET} %s\n" "$repo_name"
|
||||
((failed++))
|
||||
fi
|
||||
done
|
||||
|
||||
# --- Zusammenfassung ----------------------------------------------------
|
||||
echo
|
||||
echo "${C_BOLD}Gesamt:${C_RESET} $total Repositories"
|
||||
echo "${C_GREEN}Aktualisiert:${C_RESET} $updated"
|
||||
echo "${C_YELLOW}Uebersprungen:${C_RESET} $skipped"
|
||||
echo "${C_RED}Fehlgeschlagen:${C_RESET} $failed"
|
||||
Loading…
Add table
Add a link
Reference in a new issue