Created
June 13, 2026 14:24
-
-
Save csparker247/f3895e3e8e53e806a7091c5187c13afc to your computer and use it in GitHub Desktop.
countdown_to shell command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DESCRIPTION | |
| # ----------- | |
| # Countdown to the next occurrence of a specific time in 24-hour HH:MM format (e.g. 07:30, 14:00) | |
| # USAGE | |
| # ----- | |
| # Source this file or add this to your Shell profile (.bashprofile, .bashrc, .zshrc, ...), then run: | |
| # | |
| # countdown_to 14:00 | |
| # | |
| # Useful when you're waiting for your usage limits to reset: | |
| # | |
| # countdown_to 14:00 && claude --continue "continue what you were doing" | |
| # | |
| function countdown_to() { | |
| local input_time="$1" | |
| local now=$(date +%s) | |
| local end | |
| # Try to parse as 24-hour time (HH:MM) | |
| # We append ":00" to ensure the seconds are zeroed out. | |
| if ! end=$(date -j -f "%H:%M:%S" "${input_time}:00" +%s 2>/dev/null); then | |
| echo "Invalid format. Please use HH:MM (e.g., 14:00)." | |
| return 1 | |
| fi | |
| # 3. If the parsed time is in the past, assume it is for tomorrow (+24 hours / 86400 seconds) | |
| if (( end <= now )); then | |
| end=$((end + 86400)) | |
| fi | |
| # Optional: Let the user know exactly what time it's targeting | |
| echo "Counting down to: $(date -j -r "$end")" | |
| # 4. Run the countdown loop | |
| while (( now < end )); do | |
| printf "\t\t%s\r" "$(date -u -j -f %s $((end - now)) +%T)" | |
| sleep 0.1 | |
| now=$(date +%s) | |
| done | |
| # Print a final zeroed-out timer and a newline so the shell prompt doesn't overwrite it | |
| echo "\t\t00:00:00" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment