]> git.r.bdr.sh - rbdr/dotfiles/blob - zsh/functions/check-repos.zsh
Update dependencies
[rbdr/dotfiles] / zsh / functions / check-repos.zsh
1 #!/usr/bin/env zsh
2
3 # Function to check status of a git repository
4 check-repo() {
5 local repo_path="$1"
6 local relative_path="${repo_path#$PWD/}"
7
8 pushd "$repo_path" >/dev/null
9
10 print -n "${relative_path}: "
11
12 local status_output=$(git status --porcelain)
13
14 if [[ -z "$status_output" ]]; then
15 print -P "%F{green}CLEAN%f"
16 popd >/dev/null
17 return
18 fi
19
20 local messages=()
21
22 # Check for untracked files (??), modified files (M or space+M), and staged files (non-? non-space in first column)
23 if echo "$status_output" | grep -q "^??"; then
24 messages+=("%F{yellow}UNTRACKED%f")
25 fi
26 if echo "$status_output" | grep -q "^.[M]" || echo "$status_output" | grep -q "^M"; then
27 messages+=("%F{red}MODIFIED%f")
28 fi
29 if echo "$status_output" | grep -q "^[^? ]"; then
30 messages+=("%F{blue}STAGED%f")
31 fi
32
33 print -P "${(j: :)messages}"
34 popd >/dev/null
35 }
36
37 check-repos() {
38 local start_dir="${1:-.}"
39 fd -H -t d '^\.git$' -x echo {} | sort | sed 's/\/\.git$//' | rg -v "${SYNC_REPOS_IGNORE}" | while read -r repo_path; do
40 check-repo "$repo_path"
41 done
42 }