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"