Skip to content

Instantly share code, notes, and snippets.

@e0da
Last active August 29, 2015 14:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save e0da/1a7a8ee27dddc218f8f7 to your computer and use it in GitHub Desktop.
Audio notification of success or failure after a command finishes. Useful for long-running commands.

ding

Audio notification of success or failure after a command finishes. Useful for long-running commands.

Usage

ding rake db:migrate

To hear both sounds:

ding true
ding false

Sounds: Obviously, you have to provide your own sound files. I got mine here.

#!/bin/bash
# Customize path by setting export DING_SOUND_DIR=/path/to/sounds in .bashrc
: ${DING_SOUND_DIR:=$HOME/Dropbox/sounds}
trap 'kill 0' INT TERM KILL
success="$DING_SOUND_DIR/smw_coin.wav"
failure="$DING_SOUND_DIR/smw_pipe.wav"
player=$((which afplay &>/dev/null && echo afplay) || echo aplay)
eval "$*"
exit_code=$?
case $exit_code in
0)
sound="$success"
;;
*)
sound="$failure"
;;
esac
$player "$sound" &
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment