Skip to content

Instantly share code, notes, and snippets.

@momolog
Created January 30, 2019 21:35
Show Gist options
  • Save momolog/e12b9c25c9e976a76733cbadbf032bbb to your computer and use it in GitHub Desktop.
Save momolog/e12b9c25c9e976a76733cbadbf032bbb to your computer and use it in GitHub Desktop.
nap utility, put this into `~/bin/nap`
#!/bin/bash
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&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment