aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/timerep
blob: e09d6c1893ecf5da7ba795721e288babde52c47d (plain)
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
#!/bin/sh
TAB="$(printf '\t')"
time2tsv "$@" | sort -t"$TAB" -k4 | awk -F"$TAB" '
{
	gsub(/^\s+/, "", $4)
	gsub(/\s+$/, "", $4)
	desc = $4
	if (desc != last_desc && last_desc != "") {
		printf("%s\t%d\n", last_desc, sum)
		sum = 0
	}
	sum += $3
	last_desc = desc
}
END {
	printf("%s\t%d\n", last_desc, sum)
}
' | awk -F"$TAB" '
BEGIN {
	split("", last_path) # define empty array
}

function strip(string) {
	gsub(/^\s+/, "", string)
	gsub(/\s+$/, "", string)
	return string
}

function repeat(str, count,    i) {
	out = ""
	for (i = 0; i < count; i++) {
		out = str out
	}
	return out
}
function indent(depth,    i) {
	return repeat("  ", depth)
}

function printpath(new_path,    new, i) {
	new = 0
	for (i = 1; i <= length(new_path); i++) {
		if (last_path[i] != new_path[i]) new = 1
		if (new == 0) continue
		printf("%s%s\n", indent(i-1), new_path[i])
		last_path[i] = new_path[i]
	}
}

function timefmt(time,    fmt) {
	cmd = sprintf("timefmt %s", time)
	cmd | getline fmt
	close(cmd)
	return fmt
}

{
	len = split($1, path, "::")
	for (i = 1; i <= len; i++)
		path[i] = strip(path[i])

	task = path[len]
	delete path[len]
	depth = len - 1
	sum += $2
	duration = timefmt($2)

	printpath(path)
	printf("%-67s  %10s\n", indent(depth) task, duration)
}

BEGIN {
	printf("\033[4m%-67s\033[0m  \033[4m%10s\033[0m\n", "Description", "Total")
}

END {
	"timefmt "sum | getline duration
	printf("%67s  \033[4m%10s\033[0m\n", "", "")
	printf("%67s  %10s\n", "", duration)
}
'