-
Notifications
You must be signed in to change notification settings - Fork 66
/
file_stats.sh
62 lines (48 loc) · 1.14 KB
/
file_stats.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
function git_history {
git log $filename | grep "Date: "
}
function first_commit {
git_history | tail -1
}
function last_commit {
git_history | head -1
}
function number_of_commits {
git_history | wc -l
}
function legible_output {
# $2: filename
# $1: lines of code
# $3: number of commits
# $6: month (first)
# $7: date (first)
# $9: year (first)
# $13: month (last)
# $14: date (last)
# $16: year (last)
awk '{print $2 "," $1 "," $3 "," $6 " " $7 " " $9 "," $13 " " $14 " " $16}'
}
function lines_of_code {
echo $(wc -l $1) | sed 's/\(\/.*\)[ ]/\1_/'
}
function csv_lines_for {
# allow spaces in filenames, via file separator; re PR #7, Issue #5
STORED_IFS=$IFS
IFS=$(echo -en "\n\b")
for filename in $(find . -iname "*.$1"); do
echo "$(lines_of_code $filename) $(number_of_commits) $(first_commit) $(last_commit)" |
legible_output |
xargs echo
done
IFS=$STORED_IFS
}
function create_csv {
echo "filename,lines of code,number of commits,date of first commit,date of last commit"
for argument in "$@"
do
csv_lines_for $argument
done
}
cd $1
create_csv ${@:2:$#}
cd -