logoalt Hacker News

tclancyyesterday at 7:12 PM2 repliesview on HN

Oh, how do you automate that? I usually add a "& say done | say failed" to long-running tasks if I remember to do it.


Replies

deathanatostoday at 4:17 AM

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-...

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.)

teo_zeroyesterday at 8:38 PM

In 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\]'