-
Notifications
You must be signed in to change notification settings - Fork 17
/
ok-functions
91 lines (89 loc) · 1.93 KB
/
ok-functions
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Bash functions to display OK/ERROR and play sounds after commands finish.
# Written for Ubuntu. Should work on any Linux after changing the paths.
# They have to be sourced manually or in ~/.bashrc or ~/.profile
# See: https://github.com/rsp/scripts/blob/master/ok-functions.md
sound() {
# plays sounds in sequence and waits for them to finish
for s in $@; do
paplay $s
done
}
soundbg() {
# plays all sounds at the same time in the background
for s in $@; do
# you may need to change 0 to 1 or something else:
pacmd play-file $s 0 >/dev/null
done
}
soundloop() {
# soundloop file
# plays a sound in a loop
set +m
a=`date +%s`
{ paplay $1 & } 2>/dev/null
wait
b=`date +%s`
d=$(($b-$a))
[ $d -eq 0 ] && d=1
while :; do
pacmd play-file $1 0 >/dev/null
sleep $d
done
}
soundloopm() {
# soundloop file n
# plays a sound in a loop in intervals less than sound length by n seconds
set +m
a=`date +%s`
{ paplay $1 & } 2>/dev/null
wait
b=`date +%s`
d=$(($b-$a-$n))
[ $d -eq 0 ] && d=1
while :; do
pacmd play-file $1 0 >/dev/null
sleep $d
done
}
soundloops() {
# soundloops file n
# plays a sound in a loop every n seconds
while :; do
soundbg $1
sleep $2
done
}
sn1() {
sound /usr/share/sounds/ubuntu/stereo/dialog-information.ogg
}
sn2() {
sound /usr/share/sounds/freedesktop/stereo/complete.oga
}
sn3() {
sound /usr/share/sounds/freedesktop/stereo/suspend-error.oga
}
loop1() {
soundloop /usr/share/sounds/ubuntu/stereo/desktop-login.ogg
}
ok() {
# prints OK or ERROR and exit status of previous command
s=$?
if [[ $s = 0 ]]; then
echo OK
else
echo ERROR: $s
fi
}
oks() {
# like ok but with sounds
s=$?
sound_ok=/usr/share/sounds/ubuntu/stereo/dialog-information.ogg
sound_error=/usr/share/sounds/ubuntu/stereo/dialog-warning.ogg
if [[ $s = 0 ]]; then
echo OK
sound $sound_ok
else
echo ERROR: $s
sound $sound_error
fi
}