aboutsummaryrefslogtreecommitdiff
path: root/.local/share
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-11 21:34:26 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-11 21:34:26 +0200
commita7402a480aca41f21d95795297d713f7c39740d7 (patch)
tree59e023c35fdfb3e3882c4a1c58614edecc770815 /.local/share
parent6e57b6d76c25968bb66f11a655c3bd1d20c33041 (diff)
fix timerep
Diffstat (limited to '.local/share')
-rwxr-xr-x.local/share/bin/timefmt24
-rwxr-xr-x.local/share/bin/timerep9
2 files changed, 32 insertions, 1 deletions
diff --git a/.local/share/bin/timefmt b/.local/share/bin/timefmt
new file mode 100755
index 0000000..c78fb95
--- /dev/null
+++ b/.local/share/bin/timefmt
@@ -0,0 +1,24 @@
+#!/bin/sh
+[ $# -eq 0 ] && sum="$(cat)" || sum="$1"
+sum="$(echo "$sum" | tr -dc '[:digit:]')"
+if [ -z "$sum" ] ; then
+ echo "error: no input number"
+ exit 1
+fi
+
+fmt() {
+ # printf '%d:%02d:%02d\n' $@ | sed -e 's/^0\{2,\}//'
+ printf '%02dh%02dm%02ds\n' $@ | sed -e 's/00s$//' -e 's/^\(00.\)\+//' -e 's/^0\+//'
+}
+
+fmt $(bc <<EOF
+sum = $sum
+seconds = sum % 60
+sum = (sum - seconds) / 60
+minutes = sum % 60
+sum = (sum - minutes) / 60
+hours = sum
+print hours," ",minutes," ",seconds
+EOF
+)
+
diff --git a/.local/share/bin/timerep b/.local/share/bin/timerep
index c6b44ee..e09d6c1 100755
--- a/.local/share/bin/timerep
+++ b/.local/share/bin/timerep
@@ -47,6 +47,13 @@ function printpath(new_path, new, 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++)
@@ -56,7 +63,7 @@ function printpath(new_path, new, i) {
delete path[len]
depth = len - 1
sum += $2
- "timefmt "$2 | getline duration
+ duration = timefmt($2)
printpath(path)
printf("%-67s %10s\n", indent(depth) task, duration)