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
|
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
|
||||||
|
|
||||||
|
|
21
bin/zzz
21
bin/zzz
|
@ -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
|
if command -v slock >/dev/null; then
|
||||||
darwin*) sleep 1; pmset displaysleepnow ;;
|
pgrep slock >/dev/null || slock &
|
||||||
linux*)
|
fi
|
||||||
if command -v slock >/dev/null; then
|
sleep 1
|
||||||
pgrep slock >/dev/null || slock &
|
xset dpms force off
|
||||||
fi
|
;;
|
||||||
sleep 1
|
|
||||||
xset dpms force off
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue