←back to thread

217 points tanelpoder | 1 comments | | HN request time: 0.241s | 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. Izkata ◴[] No.26497304[source]
I do that, if it's over 60 seconds - it's not as straightforward since you also need to use PROMPT_COMMAND, a debug trap, and a variable to store the start time: https://jakemccrary.com/blog/2015/05/03/put-the-last-command...