Hacker News new | ask | show | jobs
by m-hilgendorf 1875 days ago
On MacOS

   ./very-long-task.sh && say 'success' || say 'fail'
I use it when I need to context switch and leave something running. `espeak` is an alternative for `say` on Linuxes.
4 comments

Note ShellCheck's SC2015, especially if you do stuff with permanent consequences in the place of "say":

"A && B || C is not if-then-else. C may run when A is true":

https://github.com/koalaman/shellcheck/wiki/SC2015

Interesting! Good to know, thanks. I never mix && and || in the same line, but didn't know exactly why that is!

The problem is that "In this case, if A is true but B is false, C will run."

I guess with B as "say", B will never be false, but generally it's really not the same as if-then-else.

I like this idea a lot, I just dumped a tiny shell script named 'tellme' on my mac:

    #!/bin/bash
    $@ && say 'The command finished.' || say 'Danger!  Something blew up!'
To give me a quick way to run commands and hopefully enough words to catch my attention.
As an audio-free alternative to `say 'success'`, you could use `tput bel`. Konsole, and many other terminals, can flash the screen or show a normal OS notification when a terminal bell is triggered in a non-active terminal window. This doesn't do the success/fail thing though.
I do something similar for long job on the remote server: an alias to send me an email + a rule in Outlook which opens a popup when an email with this subject is received (I haven't managed to get sound from VNC)