Hacker News new | past | comments | ask | show | jobs | submit login

And I like storing the time the prompt was printed so that I can keep track of how long a command took. When I care to keep track of when a command started, I just hit enter once or twice to get a “fresh” timestamp, then I have both an accurate start time and an accurate stop time. This is very handy if you run long jobs in a tmux session, for example.

If I rewrote the prompt each time I ran a command, I’d lose that record. (I suppose I could do the same trick in reverse and if I care to know how long a command will take, I could run it and hit enter a few times to queue up an empty command to create the same timestamp effect after the fact).




I'm not sure how it would suit your workflow, but you could try out PROMPT_COMMAND.

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....

It's executed just before the PS1 prompt is printed.

A nice idea I've seen is to use PROMPT_COMMAND to print the time a command finished (and maybe an indication of its exit status) in low-contrast text at the far right of the terminal. Then that info is there if you want to look for it, but it's not distracting.

Then you could have the best of both worlds, and it would all happen without the need to remember to create fresh prompts.


I think you could do the same thing but put the real time in place of --:--. Then when the command is run, overwrite the time with the current time. You'd only be able to see the time the most recent command took with precision, but that's usually what matters.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: