-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgit-branch-dates
More file actions
executable file
·69 lines (60 loc) · 1.5 KB
/
git-branch-dates
File metadata and controls
executable file
·69 lines (60 loc) · 1.5 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
#!/usr/bin/env bash
set -euo pipefail
sort_mode="age"
refs="refs/heads"
while [[ $# -gt 0 ]]; do
case "$1" in
-n|--name) sort_mode="name" ;;
-a|--age) sort_mode="age" ;;
-r|--remote|--remotes) refs="refs/remotes" ;;
-h|--help)
cat <<'EOF'
Usage: git-branch-date [--name|--age] [--remote]
--name sort by branch name
--age sort by last modification time (default)
--remote show remote-tracking branches
EOF
exit 0
;;
*)
echo "Unknown option: $1" >&2
exit 2
;;
esac
shift
done
case "$sort_mode" in
name) sort_key="refname" ;;
age) sort_key="-committerdate" ;;
esac
now=$(date +%s)
red=$'\033[31m'
green_bold=$'\033[1;32m'
yellow=$'\033[33m'
cyan=$'\033[36m'
dim=$'\033[2m'
reset=$'\033[0m'
git for-each-ref "$refs" \
--sort="$sort_key" \
--format='%(HEAD)|%(refname:short)|%(committerdate:unix)|%(committerdate:short)|%(committerdate:relative)' |
while IFS='|' read -r head branch ts shortdate rel; do
age_days=$(( (now - ts) / 86400 ))
if [[ "$head" == "*" ]]; then
marker="*"
bcolor="$green_bold"
else
marker=" "
bcolor="$red"
fi
printf '%s %b%-56s%b %b%6dd%b %b%s%b\n' \
"$marker" \
"$bcolor" "$branch" "$reset" \
"$yellow" "$age_days" "$reset" \
"$dim" "$shortdate" "$reset"
# printf '%s %b%-45s%b %b%6dd%b %b%-10s%b %b%s%b\n' \
# "$marker" \
# "$bcolor" "$branch" "$reset" \
# "$yellow" "$age_days" "$reset" \
# "$dim" "$shortdate" "$reset" \
# "$cyan" "$rel" "$reset"
done