Skip to content

Instantly share code, notes, and snippets.

@xrstf
Created August 12, 2025 20:28
Show Gist options
  • Save xrstf/537a4e3f5ed31241f0755089201f768e to your computer and use it in GitHub Desktop.
Save xrstf/537a4e3f5ed31241f0755089201f768e to your computer and use it in GitHub Desktop.
play sounds depending on the exit code
#!/usr/bin/env bash
set +o errexit
"${@}"
EXIT_CODE=${?}
set -o errexit
SOUNDS_DIR="$HOME/bin/sounds"
SUCCESS_SOUND="yay-6120.mp3" # https://pixabay.com/sound-effects/yay-6120/
ERROR_SOUND="error-126627.mp3" # https://pixabay.com/sound-effects/error-126627/
if [ "$EXIT_CODE" -ne 0 ]; then
pw-play "$SOUNDS_DIR/$ERROR_SOUND" &
else
pw-play "$SOUNDS_DIR/$SUCCESS_SOUND" &
fi
exit "$EXIT_CODE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment