Skip to content

Instantly share code, notes, and snippets.

@FabulousCupcake
Created October 13, 2025 02:04
Show Gist options
  • Select an option

  • Save FabulousCupcake/6e266b0bf466afe02a02687df87676bd to your computer and use it in GitHub Desktop.

Select an option

Save FabulousCupcake/6e266b0bf466afe02a02687df87676bd to your computer and use it in GitHub Desktop.
# The following bash snippet plays SFX when a matching pattern is found
# in the stdout (or stderr) when running another command
# I personally use it for input-leap / barrier
# To indicate when my cursor is locked or unlocked to the current screen
# or when it reconnects.
# Pairs of pattern and path to sfx file
declare -A SOUNDS=(
["has connected"]="ring.mp3"
["cursor locked"]="switch-on.aiff"
["cursor unlocked"]="switch-off.aiff"
)
# The notifier function
sfx() {
while IFS= read -r LINE; do
# tee it
echo "$LINE"
# look for patterns
for pat in "${!SOUNDS[@]}"; do
if [[ $LINE =~ $pat ]]; then
# play in background
local SOUND_FILE="${SOUNDS[$pat]}"
afplay "$SOUND_FILE" &
fi
done
done
}
# Usage examples
input-leaps -f | sfx
tail -f /var/log/syslog.log | sfx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment