From 20b8c2c1ad05087f802940ccb5bb405ac72964db Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 12 May 2020 17:45:39 -0400 Subject: [PATCH] Use zsh for bin/since Why depend on bc for this, when we know zsh will always be available on my nix systems. --- bin/since | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/bin/since b/bin/since index 148b8b6a..ffe053e2 100755 --- a/bin/since +++ b/bin/since @@ -1,5 +1,4 @@ -#!/usr/bin/env cached-nix-shell -#! nix-shell -i bash -p bc +#!/usr/bin/env zsh set -e (( $# > 0 )) || exit @@ -25,23 +24,15 @@ fi # Bash doesn't support floating point arithmetic like zsh does, so use bc to do # our arithmetic. -bc < 0) print weeks, "w " - if (days > 0) print days, "d " - if (hours > 0) print hours, "h " - if (minutes > 0) print minutes, "m " - print seconds, "s" -EOF +zmodload zsh/mathfunc +t=$(( abs(t) )) +weeks=$(( t / 60 / 60 / 24 / 7 )) +days=$(( t / 60 / 60 / 24 % 7 )) +hours=$(( t / 60 / 60 % 24 )) +minutes=$(( t / 60 % 60 )) +seconds=$(( t % 60 )) +(( weeks > 0 )) && echo -n "${weeks}w " +(( days > 0 )) && echo -n "${days}d " +(( hours > 0 )) && echo -n "${hours}h " +(( minutes > 0 )) && echo -n "${minutes}m " +echo -n "${seconds}s"