Created
November 14, 2023 08:26
-
-
Save JonasGroeger/6c717015f4ffd7b10a406d23347af915 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set - | |
export UPDATED_YES=✅ | |
export UPDATED_NO=❌ | |
export DIRTY_YES=🐷 | |
export DIRTY_NO=✨ | |
export REPO_TRUNCATE_CHARS=32 | |
update_repo() { | |
REPO="$1" | |
UPDATED="$UPDATED_YES" | |
DIRTY="$DIRTY_NO" | |
cd "$REPO" || exit | |
REPO_TRUNCATED="$(echo "$REPO" | awk -v len="${REPO_TRUNCATE_CHARS}" '{ if(length($0) > len) print substr($0, 1, len) "…"; else print; }')" | |
BRANCH="$(git branch --show-current)" | |
git fetch --quiet | |
if [[ -n $(git status --porcelain) ]]; then | |
DIRTY="$DIRTY_YES" | |
fi | |
if [[ "$BRANCH" =~ ^(main|master)$ && "$DIRTY" = "$DIRTY_NO" ]]; then | |
GIT_LOG_FILE="$(mktemp)" | |
git log --pretty=tformat:'%C(yellow)%>(16)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short --no-merges "${BRANCH}...origin/${BRANCH}" > "$GIT_LOG_FILE" | |
git pull --quiet --ff-only | |
else | |
UPDATED="$UPDATED_NO" | |
fi | |
printf "%7s | %$((REPO_TRUNCATE_CHARS+1))s | %7s | %s\n" "$UPDATED" "$REPO_TRUNCATED" "$DIRTY" "$BRANCH" | |
test -f "$GIT_LOG_FILE" && { cat "$GIT_LOG_FILE"; rm -f "$GIT_LOG_FILE"; } | |
} | |
export -f update_repo | |
printf "Pulled | %$((REPO_TRUNCATE_CHARS+1))s | Dirty? | Branch\n" "Project" | |
printf -- '-%.0s' {1..60}; printf '\n' | |
find . \ | |
-maxdepth 1 \ | |
-mindepth 1 \ | |
-type d \ | |
-not -path '*/.*' \ | |
-printf '%f\0' \ | |
| sort -z \ | |
| parallel -0 --jobs 8 --keep-order 'update_repo {}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment