-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitremotebranches
More file actions
executable file
·32 lines (28 loc) · 1017 Bytes
/
gitremotebranches
File metadata and controls
executable file
·32 lines (28 loc) · 1017 Bytes
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
#!/bin/bash
#
# List remote branches with last commit info, sorted by author then recency.
# Optionally filter to branches whose last commit is at least N weeks old.
set -e
case "${1:-}" in
-h|--help)
echo "Usage: ${0##*/} [min_weeks]"
exit 0 ;;
esac
min_weeks=${1:-0}
now=$(date +%s)
secs_per_week=604800
git for-each-ref --format='%(refname:short)' refs/remotes/ | while read -r branch; do
IFS='|' read -r author timestamp age <<< "$(git log -1 --format='%an|%at|%ar' "$branch")"
weeks_old=$(( (now - timestamp) / secs_per_week ))
if [ "$weeks_old" -ge "$min_weeks" ]; then
printf '%s|%s|%s|%s\n' "$author" "$timestamp" "$age" "$branch"
fi
done | sort -t'|' -k1,1 -k2,2nr | {
read -r first || exit 0
printf '%-25s %-20s %s\n' "Author" "Age" "Branch"
printf '%-25s %-20s %s\n' "------" "---" "------"
printf '%s\n' "$first"
cat
} | while IFS='|' read -r author timestamp age branch; do
printf '%-25s %-20s %s\n' "$author" "$age" "$branch"
done