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

18 lines
455 B
Text
Raw Normal View History

2022-11-18 00:39:09 -08:00
#!/bin/bash
# Usage: sleep-until <time>
2022-06-01 02:27:46 -07:00
# 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"
exit 1
2022-06-01 02:27:46 -07:00
fi
else
echo "Please input a valid date"
exit 1
2022-06-01 02:27:46 -07:00
fi