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:
parent
e169416ae4
commit
20b8c2c1ad
35
bin/since
35
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 <<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"
|
||||
|
|
Loading…
Reference in a new issue