aboutsummaryrefslogtreecommitdiff
path: root/zsh/functions/check-repos.zsh
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-12-18 21:26:19 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-12-18 21:26:19 +0100
commitfe17fef03f8c2bb44f0c2dc8f2185db6f33145f4 (patch)
tree160fb08c5d4be5384528cafe07dfbe990413c779 /zsh/functions/check-repos.zsh
parentf3e9f5c17a6ba27ae5715a566b1454031f5a10da (diff)
Add repo sync functionality
Diffstat (limited to 'zsh/functions/check-repos.zsh')
-rw-r--r--zsh/functions/check-repos.zsh42
1 files changed, 42 insertions, 0 deletions
diff --git a/zsh/functions/check-repos.zsh b/zsh/functions/check-repos.zsh
new file mode 100644
index 0000000..c5a9a10
--- /dev/null
+++ b/zsh/functions/check-repos.zsh
@@ -0,0 +1,42 @@
+#!/usr/bin/env zsh
+
+# Function to check status of a git repository
+check-repo() {
+ local repo_path="$1"
+ local relative_path="${repo_path#$PWD/}"
+
+ pushd "$repo_path" >/dev/null
+
+ print -n "${relative_path}: "
+
+ local status_output=$(git status --porcelain)
+
+ if [[ -z "$status_output" ]]; then
+ print -P "%F{green}CLEAN%f"
+ popd >/dev/null
+ return
+ fi
+
+ local messages=()
+
+ # Check for untracked files (??), modified files (M or space+M), and staged files (non-? non-space in first column)
+ if echo "$status_output" | grep -q "^??"; then
+ messages+=("%F{yellow}UNTRACKED%f")
+ fi
+ if echo "$status_output" | grep -q "^.[M]" || echo "$status_output" | grep -q "^M"; then
+ messages+=("%F{red}MODIFIED%f")
+ fi
+ if echo "$status_output" | grep -q "^[^? ]"; then
+ messages+=("%F{blue}STAGED%f")
+ fi
+
+ print -P "${(j: :)messages}"
+ popd >/dev/null
+}
+
+check-repos() {
+ local start_dir="${1:-.}"
+ fd -H -t d '^\.git$' -x echo {} | sort | sed 's/\/\.git$//' | rg -v "${SYNC_REPOS_IGNORE}" | while read -r repo_path; do
+ check-repo "$repo_path"
+ done
+}