-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathding.sh
executable file
·57 lines (51 loc) · 1.4 KB
/
ding.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Run a given command and play a sound based on it's exit code.
# By [email protected]
# Based on Jonathan Palardy's ding script from:
# https://github.com/jpalardy/dotfiles/blob/53a26cbb54dd7eb1de599a8e6ba931649452a468/bin/ding
# As presented in the following blog post from Oct 2022:
# https://blog.jpalardy.com/posts/ding/
# Play a short sound based on given exit code.
# See also https://tldp.org/LDP/abs/html/exitcodes.html
play_sound()
{
if ! type play >/dev/null; then
echo "$(basename $0): can't play sound" >&2
return
fi
case $1 in
0) play -q /usr/share/sounds/Oxygen-Sys-App-Positive.ogg;;
127) play -q /usr/share/sounds/Oxygen-Sys-File-Open-Foes.ogg;;
*) play -q /usr/share/sounds/Oxygen-Sys-App-Error-Serious-Very.ogg;;
esac
}
wrap_command()
{
"$@"
exit_code=$?
play_sound $exit_code &
exit $exit_code
}
show_help()
{
echo -e "Run a given command and play a sound based on it's exit code.\n"
echo -e "Usage: $(basename "$0") COMMAND\n"
echo """Options:
--good play good sound and exit without running any command
--fail play fail sound and exit without running any command
--help this message"""
}
#
# main
#
if [[ $# = 0 ]]; then
play_sound 0 &
exit
fi
case $1 in
--good) play_sound 0;;
--fail) play_sound 1;;
[0-9]*) play_sound $1;;
-h|--help|help) show_help;;
*) wrap_command $@;
esac