←back to thread

457 points benoitg | 4 comments | | HN request time: 0.288s | source
Show context
hiAndrewQuinn ◴[] No.44365512[source]
I like maximalist prompts, and indeed Starship is what Shell Bling Ubuntu [1] installs on a new dev machine. But they're not everyone's cup of tea.

If I wanted to recommend to someone the min-maxed, highest density thing they could add to their prompt, it would simply be the time your current prompt appeared + the amount of time the last command you ran took.

These two pieces of information together make it very easy for you (or your local sysadmin (or an LLM looking over your digital shoulder)) to piece together a log of exactly what happened when. This kind of psuedo-non-repudiation can be invaluable for debugging sessions when you least expect it.

This was a tip I distilled from Michael W. Lucas's Networking for System Administrators a few years ago, which remains my preferred recommendation for any developers looking to learn just enough about networking to not feel totally lost when talking to an actual network engineer.

Bonus nerd points if you measure time in seconds since the UNIX epoch. Very easy and fast to run time delta calculations if you do that:

    [0 1719242840] $ echo "foo"
    [0 1719242905] $ echo "fell asleep before hitting enter" && sleep 5
    [5 1719242910] $
[1]: https://github.com/hiAndrewQuinn/shell-bling-ubuntu
replies(6): >>44365588 #>>44366612 #>>44367092 #>>44368319 #>>44369209 #>>44369984 #
1. layer8 ◴[] No.44369209[source]
You could probably (I haven’t tested it) append the run time as a comment to the history using something like PROMPT_COMMAND and `history -r <(…)`, instead of cluttering the prompt with it. And the start time is already in the history, using HISTTIMEFORMAT.
replies(2): >>44370044 #>>44371860 #
2. hiAndrewQuinn ◴[] No.44370044[source]
Per the Bash `history` manpage:

    int history_write_timestamps
       If non-zero, timestamps are written to the history file, so they can be preserved between sessions.  The default value is 0, [...]
So this isn't true by default on many machines unless it is explicitly turned on. Once you do have it on, of course, then I agree.
replies(1): >>44370519 #
3. layer8 ◴[] No.44370519[source]
That’s why I wrote “using HISTTIMEFORMAT”, which turns it on. It’s reasonably common to do that.
4. bedlamite ◴[] No.44371860[source]
This is why I really appreciate tools like Atuin. It augments your history with extra data such as the working directory, exit code, time to run command.