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 #!/usr/bin/env zsh
#! nix-shell -i bash -p bc
set -e set -e
(( $# > 0 )) || exit (( $# > 0 )) || exit
@ -25,23 +24,15 @@ fi
# Bash doesn't support floating point arithmetic like zsh does, so use bc to do # Bash doesn't support floating point arithmetic like zsh does, so use bc to do
# our arithmetic. # our arithmetic.
bc <<EOF zmodload zsh/mathfunc
define abs(i) { t=$(( abs(t) ))
if (i < 0) return (-i) weeks=$(( t / 60 / 60 / 24 / 7 ))
return (i) days=$(( t / 60 / 60 / 24 % 7 ))
} hours=$(( t / 60 / 60 % 24 ))
minutes=$(( t / 60 % 60 ))
t = abs($t) seconds=$(( t % 60 ))
(( weeks > 0 )) && echo -n "${weeks}w "
weeks = t / 60 / 60 / 24 / 7 (( days > 0 )) && echo -n "${days}d "
days = t / 60 / 60 / 24 % 7 (( hours > 0 )) && echo -n "${hours}h "
hours = t / 60 / 60 % 24 (( minutes > 0 )) && echo -n "${minutes}m "
minutes = t / 60 % 60 echo -n "${seconds}s"
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