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

16 lines
430 B
Text
Raw Normal View History

2022-06-01 02:27:46 -07:00
#!/bin/sh
# Usage: sleep_until <time>
# Ex: sleep-until 3:00 pm
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 valid date"
fi