forked from rwalshe/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lastUpdated.sh
executable file
·72 lines (60 loc) · 1.75 KB
/
lastUpdated.sh
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
#! /bin/bash
function main {
local reverse=false format='%cr'
DEBUG=false
local helpstring="List files in a git repo along with when they were last updated.\n\t-d\tdebug mode (truncate input)\n\t-r\treverse sort order (default oldest first)\n\t-f\tset git date format string (e.g. %cr, %cd, etc.)\n\t-h\tdisplay this help.\n"
OPTIND=1
while getopts "drf:h" opt; do
case $opt in
d) DEBUG=true ;;
r) reverse=true ;;
f) format=$OPTARG ;;
h) echo -e $helpstring; return;;
*) return 1;;
esac
done
shift $((OPTIND-1))
readonly DEBUG
# If debug is only process 50 filenames
if $DEBUG; then
FILTER='head -n 50'
else
FILTER='tee'
fi
ack_file_info $format | clean_input | sort_cleaned_input $reverse | clean_output
commit
}
# Use ack's -f flag to just list files. We could use pretty much anything here,
# but I'm tempted to allow passing args to ack later
function ack_file_info {
local format="$1"
echo commit, age, hash, filename > .github/metrics/log.csv
ack -g '^((astro)|(software/)|(learn))' -t markdown |\
$FILTER |\
xargs -I § git log -1 --pretty="format:%ct,${format},%h,§;" §
}
# I'm not sure what goes one above, but on Mac OSX, the output of xargs loses
# its newlines when it's piped through a filter. So replace ; with \n as a
# bodge to fix this.
function clean_input {
tr ';' '\n'
}
function sort_cleaned_input {
local reverse="$1"
if $reverse; then
sort -r
else
sort
fi
}
# Trim commit timestamps from output
function clean_output {
cut -f 2- >> .github/metrics/log.csv
sleep 10
}
function commit {
wait
git add .
git status
}
main "$@"