From 01a1ed449f72740d81cda58357936639ce8b79cd Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sun, 22 Mar 2020 23:23:28 +0100 Subject: Include duration of installation process --- lib/actions/install.bash | 8 +++++++- lib/util.bash | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/actions/install.bash b/lib/actions/install.bash index b2faefd..8f6993b 100644 --- a/lib/actions/install.bash +++ b/lib/actions/install.bash @@ -16,6 +16,8 @@ action() { local OPTIND local prefix_absolute local modules + local init + local duration while getopts ":b:p:" opt do @@ -33,6 +35,7 @@ action() { prefix_absolute="$(CDPATH="" cd -- "$RSTAR_PREFIX" && pwd -P)" info "Installing Raku in $prefix_absolute" + init="$(date +%s)" # Compile all core components for component in moarvm nqp rakudo @@ -73,9 +76,12 @@ action() { done fi + duration="$(pp_duration "$init")" + # Friendly message - # TODO: Add information on the time it took" info "Rakudo Star has been installed into $prefix_absolute!" + info "The installation took $duration." + info "" info "You may need to add the following paths to your \$PATH:" info " $prefix_absolute/bin" info " $prefix_absolute/share/perl6/site/bin" 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() { -- cgit v1.1