From 899b76576e5dfa23fee90ed113b29cdb8efc2408 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 12 Apr 2020 16:09:31 -0400 Subject: [PATCH] Remove macos-isms from scripts I don't use mac anymore. Also installs bc when you use bin/since --- bin/since | 20 ++++++-------------- bin/zzz | 21 +++++++-------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/bin/since b/bin/since index d56a6585..148b8b6a 100755 --- a/bin/since +++ b/bin/since @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env cached-nix-shell +#! nix-shell -i bash -p bc set -e (( $# > 0 )) || exit @@ -10,28 +11,20 @@ set -e # TODO: A help fallback # 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 (( $# == 1 )) && [[ -f $1 ]] && arg=reference || arg=date if [[ $1 == -- ]]; then t="$2" else - now=$($date +%s) - then=$($date --$arg="$*" +%s) + now=$(date +%s) + then=$(date --$arg="$*" +%s) t=$(( now - then )) 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 < 0) print minutes, "m " print seconds, "s" EOF - diff --git a/bin/zzz b/bin/zzz index f2ae079f..7f78eb4d 100755 --- a/bin/zzz +++ b/bin/zzz @@ -11,20 +11,13 @@ if [[ $1 == -h ]]; then echo " $bin -f # put computer to sleep" elif [[ $1 == -f ]]; then echo "Going to sleep..." - case $OSTYPE in - darwin*) pmset sleepnow ;; - linux*) systemctl suspend ;; - esac + systemctl suspend else echo "Shutting my eyes..." - case $OSTYPE in - darwin*) sleep 1; pmset displaysleepnow ;; - linux*) - if command -v slock >/dev/null; then - pgrep slock >/dev/null || slock & - fi - sleep 1 - xset dpms force off - ;; - esac + if command -v slock >/dev/null; then + pgrep slock >/dev/null || slock & + fi + sleep 1 + xset dpms force off + ;; fi