dotfiles/.config/shell/functions/sleep-until

18 lines
475 B
Text
Raw Normal View History

2022-04-29 01:18:16 -07:00
#!/bin/sh
# Usage: sleep_until <time>
# Ex: sleep_until 3:00 pm
sleep_until() {
if [ -n "$1" ] && date --date="$*" > /dev/null 2>&1; then
2022-04-29 02:57:43 -07:00
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
2022-04-29 01:18:16 -07:00
else
echo "Please input a date"
fi
}