4 ms·
As a counterpoint, one of the most useful customizations I've made to my prompt is to emit the exit status of the prior command. Knowing that something failed i
by deathanatos 1y ago
As a counterpoint, one of the most useful customizations I've made to my prompt is to emit the exit status of the prior command. Knowing that something failed is a useful signal, esp. when sometimes the thing failing just fails to emit any output that indicates that it failed.
I only emit it if the prior command fails, too, so it doesn't clutter things the 90% of the time things are working.
» true
» false
(last command returned 1.)
»
I also translate signals, so I get "last command exited on SIGSEGV", or so.
It's also useful the other way: when a program emits and error and exits with "success".
- __float 1y agoI like the exit code feature a lot; Starship does that with my config in a subtle color change. My shell customization is largely throwing Starship in (so it looks the same on all the machines I use -- Ubuntu servers at work, macOS at home, nixOS/Fedora/etc. servers for personal use.) and a starship.toml I wrote once and now leave alone.
- m000 1y agoThat's useful indeed. Did you custom-code it, or is it e.g. an ohmyzsh plugin or something?
- deathanatos 1y agoI custom coded it. (Details: https://news.ycombinator.com/item?id=44373575 https://news.ycombinator.com/item?id=44373575)
- tclancy 1y agoOh, how do you automate that? I usually add a "& say done | say failed" to long-running tasks if I remember to do it.
- teo_zero 1y agoIn bash, it's enough to remember that $? expands to the exit code of the previous command, and $((x)) evaluate x as an integer expression, including the ternary operator x?y:z. For example the following prints the exit code in green if zero, in red otherwise: PS1='\[\e[$(($??31:32))m\]$? \[\e[39m\]'
- deathanatos 1y agohttps://github.com/thanatos/dotfiles/blob/master/shell/zsh/prompt-alpha#L108-L174 https://github.com/thanatos/dotfiles/blob/master/shell/zsh/p... That was my prompt when it was written in zsh. Sort of like TFA, I've since moved to Rust: https://github.com/thanatos/dotfiles/blob/master/zsh-prompt-in-rust/src/prompt.rs#L242-L270 https://github.com/thanatos/dotfiles/blob/master/zsh-prompt-... I think (if I am reading TFA's code right) unlike the article, I'm using zsh's module functionality, so the Rust here is a .so that is loaded directly into the shell's memory. (I.e., I do not have to fork/exec a separate Rust bin to compute the prompt, though I think zsh might fork-but-not-exec for computing the prompt itself.) The latter is, of course, somewhat more complicated in some senses. (Esp. on macOS, which work forces me to use, where dlopen(2) is just utterly insane.)
- wocram 1y agoThis and command duration if the command ran longer than 10 seconds are the most useful things to add.