Skip to content

Releases: didvc/sleepgo

Release list

v1.0.0

Choose a tag to compare

@didvc didvc released this 30 Aug 18:36

sleep has exactly two flags, --help and --version, so a long wait happens behind a blank line with no way to ask how much of it is left. sleepgo is a drop-in replacement that adds the flag.

go install github.com/didvc/sleepgo@latest

What you get

sleepgo -p 30      # progress bar
sleepgo -c 5m      # countdown only
sleepgo -v 2h      # print the wake-up time, then wait
sleepgo 1m 30s     # silent, exactly like sleep

Drop-in by default

With no flags it behaves like sleep, so alias sleep=sleepgo is safe. Duration operands match GNU coreutils: the s/m/h/d suffixes, several operands added together, fractions and exponents, inf and infinity. The awkward corners match too — 0x10 is 16 seconds and 0x1d is 29 seconds because that is how C's strtod reads them, nan and negatives are rejected with the same message, and -1 is an unknown option rather than a negative duration. Every form was diffed against GNU coreutils 8.30.

Set SLEEPGO_PROGRESS=1 if you would rather have the bar by default.

Behaviour worth knowing

The display is written to stderr, so pipes and redirection of stdout keep working. Off a terminal it degrades to one line before and one after instead of filling a log file with carriage returns.

Drawing a bar does not make the wait longer. Timing is anchored to a single monotonic deadline taken at the start, so sleepgo -p 1 and sleep 1 both land at about 1004 ms, and a clock change during the wait leaves its length alone.

Ctrl-C clears the bar, restores the cursor, and ends the process by the signal, so it still breaks out of a shell loop the way sleep does. Ctrl-Z hands the terminal back before stopping, and fg picks the bar up where it left off.

Cost

A silent sleep wakes once and costs one timer. A countdown wakes once per second, timed to the moment the digit changes. Process startup is around 0.9 ms against 0.47 ms for GNU sleep, which is the Go runtime starting up; it is noise for sleepgo 30 and it is the whole cost for sleepgo 0.001 in a tight loop, so keep spawning thousands of tiny sleeps out of your hot paths.

Platforms

Tested on Linux. Builds for macOS, the BSDs and Windows on amd64 and arm64. The Windows display has not been exercised in the wild and reports are welcome.

Licensed under MPL-2.0.