←back to thread

217 points tanelpoder | 1 comments | | HN request time: 0.213s | source
Show context
scudd ◴[] No.26492906[source]
TIL: You can use `echo $?` to get the last process's exit code.
replies(2): >>26493051 #>>26493264 #
enriquto ◴[] No.26493051[source]
this is actually the most useful thing to put in your prompt (much more than your username, the current directory and other redundant stuff), as in PS1='$?\$ '
replies(2): >>26495670 #>>26497266 #
chriswarbo ◴[] No.26495670[source]
I used to leave my prompt alone until recently, but was inspired by https://news.ycombinator.com/item?id=26059023 to at least conservatively raise my expectations.

Now my prompts start with the current UNIX time, coloured red if the previous exit code was non-zero, or green if it was zero. This gives me instant feedback on success/failure, and lets me retroactively see how long a command took (without having to re-run it with `time`).

replies(1): >>26496293 #
enriquto ◴[] No.26496293[source]
wouldn't it be more useful to show the time difference? Or maybe only show it in case it is larger than 1 second?
replies(2): >>26497304 #>>26500232 #
1. chriswarbo ◴[] No.26500232[source]
Duration and start time can both be useful, and the former can be calculated from the latter as needed. Plus it's easier to implement (stateless) and has consistent alignment (always 10 digits).

BTW here's the function I use:

``` showTime() { if [[ "$?" -eq 0 ]] then TIMECOLOR='\e[92m' else TIMECOLOR='\e[91m' fi echo -e "$TIMECOLOR$(date '+%s')\e[0m" } ```