Five More Minutes

bedtime is a terminal command that puts your machine to sleep at the time you set. One minute before that time, asking opens, and you can type five more minutes. Each grant is half the one before: the first is 15 minutes, then 7 minutes 30 seconds, then 3 minutes 45 seconds, down to 14.062 seconds. Nothing of 10 seconds or less is granted, so there are seven grants, and the most that can ever be granted in total is 30 minutes. It is never reached. Every start, request and end goes into a plain tab-separated ledger, and a restart reads the ledger back, so stopping the program does not return a grant. It is one Go program built from the standard library only (Go 1.22 or later), for macOS (pmset) and Linux (systemctl, loginctl).

Run

go build -o bedtime .
./bedtime 23:00                  # waits, answers requests, then suspends; falls back to lock
./bedtime 23:00 --dry-run        # prints every sentence the night can say; waits for nothing, writes nothing
./bedtime 23:00 --lock           # locks instead of suspending
./bedtime 23:00 --then "<cmd>"   # runs the command with sh -c instead (hibernate, shutdown, a test)
./bedtime log                    # one row per night

Real input: the real wall clock and local time zone, the lines you type, the ledger file ($BEDTIME_LEDGER, else $XDG_STATE_HOME/bedtime/ledger.tsv, else ~/.local/state/bedtime/ledger.tsv) and the machine's own sleep and lock commands. --clock-start <YYYY-MM-DDTHH:MM:SS> and --clock-speed <n> replace the clock with a simulated one for testing only; the first line then says so, and a simulated live run refuses to start unless BEDTIME_LEDGER names its own ledger.

The rule is fixed and has no options: first grant 900000 ms, each next one halved with integer division, a grant only if it is above 10000 ms, ceiling 1800000 ms, asking opens 60000 ms before the deadline. A grant moves the deadline itself, not the moment you asked.

Test

go test ./...          # the series, the wording, the resume rules, the log, one run on a fake clock
go build -o bedtime . && test/e2e.sh        # one whole night at 60x, answered line by line (about 32 s)
test/checks.sh         # build hygiene, dry run, restarts, requests, the fallback chain with stubs
test/checks.sh real    # the same plus one real-clock run of about two minutes
test/render.sh         # wraps the captured output in out/ into out/terminal.html for screenshots

test/checks.sh replaces systemctl and loginctl with stubs for the action checks. Do not run the plain command without --then on a machine you do not want to sleep.

Colophon

Set in whatever monospace your terminal already has. No colour, no animation, no sound. Every grant issued during testing was issued on a clock that did not exist. The one night on a real clock lasted two minutes and asked for nothing. The eleven milliseconds were looked for and not found.

normal is dead

Files