Using $PROMPT_COMMAND to beep depending on success/failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stumbled on this one today thanks to @climagic on Twitter.  If you
want to have your machine give you one tone if the previous command
succeeded (had an exit-status of 0) and a different tone if the
previous command failed (had a non-zero exit status), you can put the
following one-liner in your .bashrc file:

PROMPT_COMMAND='[ "$?" == 0 ] && play -qn synth sin F3 trim 0 0 0.1
fade 0 0.1 0.05 vol 0.2 || play -qn synth square F4 trim 0 0.1 fade 0
0.1 0.05'

This uses the `play` command from the `sox` package.  There are a
number of tweaks you can make to change the tones, timbres,
wave-form, volume, duration, etc.  The above uses an F3 sine-wave at
20% volume for success and an F4 square-wave at 100% volume for
failure.

To test it out, use the `true` and `false` commands (they don't do
anything other than exit with a particular zero/non-zero exit code).

But here's hoping someone here finds it useful.

-tim



_______________________________________________
Blinux-list mailing list
Blinux-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/blinux-list



[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]