For MacOS:
#!/bin/bash
# install in /usr/local/bin/nap
if [ -z $1 ]; then
echo "No time provided. Usage: nap [-cl] [minutes]"
exit 2
fi
if [[ $1 == *c ]]; then
echo Cancelling sleep. PIDs \(if any\): `pgrep -f "nap"`
pkill -f "nap"
exit 0
fi
if [[ $1 == *l ]]; then
ps -Af | grep nap
exit 0
fi
time=$(($1 * 60))
echo Sleeping in $1 minutes...
sleep $time && pmset sleepnow&
I wrote this 10+ years ago, still use it every day.