Use zsh for bin/since

Why depend on bc for this, when we know zsh will always be available on
my nix systems.
This commit is contained in:
Henrik Lissner 2020-05-12 17:45:39 -04:00
parent e169416ae4
commit 20b8c2c1ad
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -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 <<EOF
define abs(i) {
if (i < 0) return (-i)
return (i)
}
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
if (weeks > 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"