aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/timerep
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-11 19:52:05 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-11 19:52:05 +0200
commit6e57b6d76c25968bb66f11a655c3bd1d20c33041 (patch)
treed3c10997ba9eec4f8d7ad5ec6bc8bad6ac1cf9bd /.local/share/bin/timerep
parent3bb5f72a369cb2825a2d68e536103470b7426d58 (diff)
add more time.txt scripts
Diffstat (limited to '.local/share/bin/timerep')
-rwxr-xr-x.local/share/bin/timerep75
1 files changed, 75 insertions, 0 deletions
diff --git a/.local/share/bin/timerep b/.local/share/bin/timerep
new file mode 100755
index 0000000..c6b44ee
--- /dev/null
+++ b/.local/share/bin/timerep
@@ -0,0 +1,75 @@
+#!/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]
+ }
+}
+
+{
+ 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
+ "timefmt "$2 | getline duration
+
+ 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)
+}
+'
+