Remove macos-isms from scripts

I don't use mac anymore.

Also installs bc when you use bin/since
This commit is contained in:
Henrik Lissner 2020-04-12 16:09:31 -04:00
parent a5d776c0ea
commit 899b76576e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 13 additions and 28 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env cached-nix-shell
#! nix-shell -i bash -p bc
set -e set -e
(( $# > 0 )) || exit (( $# > 0 )) || exit
@ -10,28 +11,20 @@ set -e
# TODO: A help fallback # TODO: A help fallback
# TODO: Options parsing? # TODO: Options parsing?
# `date` on OSX does not have the --date parameter
date=date
if [[ $OSTYPE == darwin* ]]; then
date=gdate
elif ! command -v $date >/dev/null; then
echo "Unsupported system"
exit 1
fi
# If given a file, give time since last modification # If given a file, give time since last modification
(( $# == 1 )) && [[ -f $1 ]] && arg=reference || arg=date (( $# == 1 )) && [[ -f $1 ]] && arg=reference || arg=date
if [[ $1 == -- ]]; then if [[ $1 == -- ]]; then
t="$2" t="$2"
else else
now=$($date +%s) now=$(date +%s)
then=$($date --$arg="$*" +%s) then=$(date --$arg="$*" +%s)
t=$(( now - then )) t=$(( now - then ))
fi fi
# Bash doesn't support floating point arithmetic like zsh does, therefore: # Bash doesn't support floating point arithmetic like zsh does, so use bc to do
# our arithmetic.
bc <<EOF bc <<EOF
define abs(i) { define abs(i) {
if (i < 0) return (-i) if (i < 0) return (-i)
@ -52,4 +45,3 @@ bc <<EOF
if (minutes > 0) print minutes, "m " if (minutes > 0) print minutes, "m "
print seconds, "s" print seconds, "s"
EOF EOF

View file

@ -11,20 +11,13 @@ if [[ $1 == -h ]]; then
echo " $bin -f # put computer to sleep" echo " $bin -f # put computer to sleep"
elif [[ $1 == -f ]]; then elif [[ $1 == -f ]]; then
echo "Going to sleep..." echo "Going to sleep..."
case $OSTYPE in systemctl suspend
darwin*) pmset sleepnow ;;
linux*) systemctl suspend ;;
esac
else else
echo "Shutting my eyes..." echo "Shutting my eyes..."
case $OSTYPE in
darwin*) sleep 1; pmset displaysleepnow ;;
linux*)
if command -v slock >/dev/null; then if command -v slock >/dev/null; then
pgrep slock >/dev/null || slock & pgrep slock >/dev/null || slock &
fi fi
sleep 1 sleep 1
xset dpms force off xset dpms force off
;; ;;
esac
fi fi