diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
| commit | e43eb1177872f52e949fb5f0f93396ed94b0d093 (patch) | |
| tree | 78b73af6a989fa2996d71b112e161b70d35081ef /home/dot_local/share/bin/executable_timerep | |
| parent | 2f14a896e4b897bd747c24d7ad8e9e7bb3237d03 (diff) | |
move to chezmoi
Diffstat (limited to 'home/dot_local/share/bin/executable_timerep')
| -rw-r--r-- | home/dot_local/share/bin/executable_timerep | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/home/dot_local/share/bin/executable_timerep b/home/dot_local/share/bin/executable_timerep new file mode 100644 index 0000000..e09d6c1 --- /dev/null +++ b/home/dot_local/share/bin/executable_timerep @@ -0,0 +1,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) +} +' + |