dotfiles/.config/shell/functions/sleep-until
2022-04-29 02:58:55 -07:00

17 lines
475 B
Bash

#!/bin/sh
# Usage: sleep_until <time>
# Ex: sleep_until 3:00 pm
sleep_until() {
if [ -n "$1" ] && date --date="$*" > /dev/null 2>&1; then
SLEEP_TIME="$(( $(date -f - +%s- <<< "$*"$'\nnow') 0 ))"
if [ "$SLEEP_TIME" -gt 0 ]; then
echo "Sleeping until: $(date --date="$*") (${SLEEP_TIME}s)"
sleep "$SLEEP_TIME"
else
echo "Sadly, you cannot sleep to a time in the past"
fi
else
echo "Please input a date"
fi
}