36 ms·
I used to use a colored indicator for the exit status, but a while ago I switched to a multiline prompt: (last command returned 1.) » Or, if the previous
by deathanatos 5y ago
I used to use a colored indicator for the exit status, but a while ago I switched to a multiline prompt:
(last command returned 1.)
»
Or, if the previous command terminates due to a signal:
(last command got signal SIGTERM.)
»
Color doesn't survive c/p in practically any medium, and the exit status is useful when showing things to co-workers.
The bigger hint also highlights when a command unexpectedly errors (e.g., while emitting text to the effect of "Success!") and the opposite case, where a command appears to fail and exits with success anyways.
- yjftsjthsd-h 5y agoOh, that's very nice. By any chance have you posted your dotfiles somewhere so that I can steal it?
- deathanatos 5y agohttps://github.com/thanatos/dotfiles/blob/master/shell/zsh/prompt-alpha#L108-L171 https://github.com/thanatos/dotfiles/blob/master/shell/zsh/p... I've tried to highlight roughly the relevant bits. The basics of it is that we lazy-load an associative array between exit statuses that are signals and their prettified names. (Which we more or less build by querying Python, to get at what's, essentially, defined in signal.h.) Once we have that assoc. array, when we get a non-zero exit, we see if it's in the array. If it is, look up the pretty name, print message. If not, just print message with raw exit status. Red & bold so it shows up. (Should probably also use bright red, too. But my work laptop is macOS, & so it's iTerm2, and iTerm2 interprets "bold" to mean "bright & bold".) I also use zsh, which is able to be considerably more expressive in what it can accomplish in a PS1 than bash can. Note that the syntax, ${+VAR} which appears in there is zsh-specific. It can be done in bash, but it isn't as neat. I don't recall if bash has associative arrays or just arrays, too…
- tom_ 5y agoI've been doing this a long time in 4NT. PROMPT=[$r][ $P ][ $t ]$_$g Appearance is along these lines: [0][ C:\bin\4nt ][ 15:30:07 ] > Super useful. It's good to get advance warning of strange exit codes when trying things out interactively with a view to using them in some automated process. The exit code also shows the exception type if the process terminates due to an exception - alway handy to know. I also like always having the same amount of space for the command, visually, regardless of the working folder.