From 42c7f5311188faaefb3c9de0a0372855dc58ddfc Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 22 Oct 2020 11:38:26 +0200 Subject: New function --- functions/humanize_duration.fish | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 functions/humanize_duration.fish (limited to 'functions/humanize_duration.fish') diff --git a/functions/humanize_duration.fish b/functions/humanize_duration.fish new file mode 100644 index 0000000..eeb999f --- /dev/null +++ b/functions/humanize_duration.fish @@ -0,0 +1,19 @@ +function humanize_duration -d "Make a time interval human readable" + command awk ' + function hmTime(time, stamp) { + split("h:m:s:ms", units, ":") + for (i = 2; i >= -1; i--) { + if (t = int( i < 0 ? time % 1000 : time / (60 ^ i * 1000) % 60 )) { + stamp = stamp t units[sqrt((i - 2) ^ 2) + 1] " " + } + } + if (stamp ~ /^ *$/) { + return "0ms" + } + return substr(stamp, 1, length(stamp) - 1) + } + { + print hmTime($0) + } + ' +end -- cgit v1.2.3-54-g00ecf