-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsist
executable file
·62 lines (50 loc) · 1.01 KB
/
insist
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
#!/bin/zsh -f
# Run a command until it returns a successful exit value.
try=0
sound=false
while [[ ${#@} -gt 0 ]]; do
arg=$1
shift 1
case $arg in
--) break ;;
-s) sound=true ;;
esac
done
command_=$@
if [[ -z $command_ ]]; then
echo "usage: insist [-s] -- command"
exit 1
fi
function play() {
local file=$1
$sound && aplay -q -D 'pulse' $file &!
}
function fail() {
printf "[Failed attempt $try]\n"
mplayer -really-quiet "/home/majoh/media/sound/Sad Trombone Sound Effect - FAIL Sound - Fail Horns.mp3" &!
}
function success() {
printf "[Success after $try attempts]\n"
[[ $try -gt 0 ]] \
&& mplayer -really-quiet "/home/majoh/media/sound/Stadium Applause 1 Sound Effect.mp3" &!
}
function wait() {
local retries=$1
local wait=$[1.3 ** retries]
printf "[Waiting %0.2f seconds before next try]\n" $wait
sleep $wait
}
while true; do
eval $command_
case $? in
0) success; exit 0 ;;
127)
fail
echo "Command not found" >&2
exit 127
;;
*) fail ;;
esac
try=$[try+1]
wait $try
done