Most active commenters
  • bayindirh(5)
  • hiAndrewQuinn(4)
  • stirfish(3)

←back to thread

457 points benoitg | 19 comments | | HN request time: 0.003s | source | bottom
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 #
skydhash ◴[] No.44365588[source]
For personal workstation, the current directory is enough. Maybe I change the color based the status of the last command. That’s pretty much the only information I need before entering any command. Everything else can be accessed when I really need it.
replies(3): >>44365629 #>>44365734 #>>44365877 #
1. meesles ◴[] No.44365877[source]
Problem is you can't get timestamps and run times of your commands 'when you really need it', unlike almost everything else
replies(4): >>44365985 #>>44366544 #>>44366632 #>>44367249 #
2. bayindirh ◴[] No.44365985[source]
Why the timestamps are that important? Honestly asking.

You can always time your commands with "time".

replies(2): >>44366033 #>>44366052 #
3. stirfish ◴[] No.44366033[source]
I personally use a modified zbell (in zsh) to give me a notification when a command finishes after 30 seconds, and send me an email if it takes over 2 minutes.
replies(1): >>44366109 #
4. bertmuthalaly ◴[] No.44366052[source]
When you’re debugging, especially a complex system, especially during an outage or postmortem, understanding when your commands executed relative to when your log lines appeared is really helpful.
replies(4): >>44366096 #>>44366468 #>>44366844 #>>44368978 #
5. bayindirh ◴[] No.44366096{3}[source]
Oh, that's an interesting use case, alright.
6. bayindirh ◴[] No.44366109{3}[source]
I generally use Konsole's "notify when program exits" feature. For longer tasks, I have a small tool which I pipe to, and it sends me push notification with the output (if I prefer).
replies(1): >>44367373 #
7. styluss ◴[] No.44366468{3}[source]
sounds like your describing https://linux.die.net/man/1/ts
8. horsawlarway ◴[] No.44366544[source]
For a personal workstation - you should never "really need it".

It's a personal machine and should be treated as disposable. Doing anything less is fairly irresponsible.

So sure - turn on timestamps for your ssh bastion (although it should be in the logs already...), or turn them on for the ci/cd pipeline (not that you should need them there anyways, since it should be dumping tons of timing info already).

But a personal machine? Plain ol' ">" is plenty.

Not that there's anything wrong with a maximal prompt either... I've definitely done the "configure all the powerline settings!" thing. But I also don't mind a simple ">" or "#".

9. hiAndrewQuinn ◴[] No.44366632[source]
Well, that's why you build it into the prompt. So you don't give yourself the opportunity to forget.
10. kccqzy ◴[] No.44366844{3}[source]
That's a poor and hacky substitute of using Linux audit features. It's perhaps the right robustness/complexity trade off for my personal machine, but for work they likely already have audit features turned on and you can access the timing from there.
replies(1): >>44367163 #
11. hiAndrewQuinn ◴[] No.44367163{4}[source]
I think you need to put a number on "likely", here. 80% of all workplaces, maybe? Even that seems a little high. There are a surprising number of devs who have never even heard of auditd. It's just not the kind of thing most people come across in their day to day work unless they go digging for it, or come from a security or DevOps background or something.
12. mechanicum ◴[] No.44367249[source]
As an alternative, perennial HN recommendation atuin (https://atuin.sh) logs time, duration and exit code (among other data) for every command.

That way you only have to look at it when you need it, and you can also figure out what you were doing last week/month/year if necessary.

replies(1): >>44373066 #
13. stirfish ◴[] No.44367373{4}[source]
I had a tool I'd pipe to, but I'd often only think about it after I'd realize that the command was going to take a while. A push notification sound cool; I used email because I knew how to hack it together with curl.

Here's one zbell implementation, not sure it's the original but it looks like it does the trick: https://gist.github.com/oknowton/8346801

replies(1): >>44387404 #
14. xorcist ◴[] No.44368978{3}[source]
That's a good reason to have timestamps in the history, which you should.

Something like

  export HISTFILESIZE=
  export HISTSIZE=
  export HISTTIMEFORMAT="[%F %T] "
  shopt -s histappend
really ought to be default in bash.

It's not as clear why you need it in the interactive prompt.

replies(1): >>44370082 #
15. hiAndrewQuinn ◴[] No.44370082{4}[source]
I didn't make it quite as clear as I should: the reason to have it in the prompt is mostly so that you, or someone you're working with, can spot a trend you may not consciously think to look for if the timestamps weren't in front of you.

It sounds silly, but it has saved my butt more than once. Especially if you have bugs that e.g. only show up once per hour on the hour, and are otherwise fine.

16. magarnicle ◴[] No.44373066[source]
After mucking around for an hour trying to get this information into my prompt, I realised atuin already had it.
17. bayindirh ◴[] No.44387404{5}[source]
Thanks for sharing the bell. I'll take a look. If you want to try push notifications, I use https://pushover.net as a service.

I developed the tool myself, and it's at https://git.sr.ht/~bayindirh/nudge if you feel like checking it out.

If you want to host the whole push notification infrastructure, you can look at https://ntfy.sh which also can be integrated with cURL.

replies(1): >>44387728 #
18. stirfish ◴[] No.44387728{6}[source]
This is incredibly helpful, thank you. I had no idea push notifications was something I could self-host.
replies(1): >>44387832 #
19. bayindirh ◴[] No.44387832{7}[source]
You're absolutely welcome. Me neither. If I could find ntfy.sh earlier, I'd have written nudge for it, not for Pushover.