-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat
More file actions
executable file
·91 lines (69 loc) · 2.23 KB
/
stat
File metadata and controls
executable file
·91 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# set -e
REPOS_FILE="$STATUS_REPO_LIST"
yellow="\e[93m"
_0="\e[0m"
separator="********************************************************************************"
checkmark="✅"
cross="❌"
ahead_behind="🔄"
# Create temp directory for ordered output
tmpdir=$(mktemp -d)
declare -i index=0
main() {
[[ -f "$REPOS_FILE" ]] || { echo "$REPOS_FILE not found. Create one."; exit 1; }
# clear -x
echo -e "Fetching repositories in parallel..."
process_repos 2>/dev/null
display_results
clean_up
}
process_repos() {
while IFS='=' read -r key value; do
[[ "$key" =~ ^# ]] && continue
[[ -z "$key" || -z "$value" ]] && continue
key=$(tr -d '[:space:]' <<< "$key")
value=$(tr -d '[:space:]' <<< "$value")
path="${value}"
# Store repo info with index
declare -gA repos["$index"]="$key:$path"
# Start background process
( check_git_status "$path" "$key" "$1" > "${tmpdir}/${index}.log" ) &
((index++))
done < "$REPOS_FILE"
wait
}
check_git_status() {
local repo_dir="$1" repo_name="$2" verbose="$3"
# Parallel fetch
git -C "$repo_dir" fetch > /dev/null 2>&1
# Get status
local status_output=$(git -C "$repo_dir" status -s)
local ahead_behind_output=$(git -C "$repo_dir" status -sb | grep -E 'ahead|behind')
# Generate output
if [[ -z "$status_output" && -z "$ahead_behind_output" ]]; then
printf "%-12s: %s\n" "$repo_name" "$checkmark"
else
printf "%-12s: %s\n" "$repo_name" "$cross"
[[ -n "$ahead_behind_output" ]] && printf " %-10s: %s\n" "Outdated" "$ahead_behind"
[[ "$verbose" == '-v' ]] && git -C "$repo_dir" status -s
fi
}
display_results() {
for ((i=0; i<index; i++)); do
# Get original repo info
IFS=':' read -r key path <<< "${repos[$i]}"
# Show results in original order
if [[ -f "${tmpdir}/${i}.log" ]]; then
cat "${tmpdir}/${i}.log"
else
echo -e "${yellow}${key}: ⚠ Processing failed${_0}"
fi
done
}
clean_up() {
rm -rf "$tmpdir"
}
trap 'clean_up; exit 1' INT TERM
main "$@"
echo "REPLACE WITH LAZYGIT OR CRONTAB"