Remove macos-isms from scripts
I don't use mac anymore. Also installs bc when you use bin/since
This commit is contained in:
parent
a5d776c0ea
commit
899b76576e
20
bin/since
20
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 <<EOF
|
||||
define abs(i) {
|
||||
if (i < 0) return (-i)
|
||||
|
@ -52,4 +45,3 @@ bc <<EOF
|
|||
if (minutes > 0) print minutes, "m "
|
||||
print seconds, "s"
|
||||
EOF
|
||||
|
||||
|
|
21
bin/zzz
21
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
|
||||
|
|
Loading…
Reference in a new issue