diff options
author | Patrick Spek <p.spek@tyil.nl> | 2020-03-22 23:23:28 +0100 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2020-03-22 23:23:28 +0100 |
commit | 01a1ed449f72740d81cda58357936639ce8b79cd (patch) | |
tree | 9b9e4dbdc3c5a43b65a72c7882b3a697061ed8bc /lib/util.bash | |
parent | efebfd58938fc512e300cbdafd25e01e61bd4157 (diff) |
Include duration of installation process
Diffstat (limited to 'lib/util.bash')
-rw-r--r-- | lib/util.bash | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/util.bash b/lib/util.bash index 8ca1a5e..7ab0bc1 100644 --- a/lib/util.bash +++ b/lib/util.bash @@ -74,6 +74,28 @@ fetch() { return $exit_code } +# Pretty print a duration between a starting point (in seconds) and an end +# point (in seconds). If no end point is given, the current time will be used. +# A good way to get a current timestamp in seconds is through date's "%s" +# format. +pp_duration() { + local start=$1 + local end=$2 + local diff + + if [[ -z "$end" ]] + then + end="$(date +%s)" + fi + + diff=$((end - start)) + + printf "%dh %02dm %02ds\n" \ + "$((diff / 60 / 60))" \ + "$((diff / 60))" \ + "$((diff % 60))" +} + # Create a temporary directory. Similar to tempfile, but you'll get a directory # instead. tmpdir() { |