-
Notifications
You must be signed in to change notification settings - Fork 5
/
waiter
72 lines (56 loc) · 1.21 KB
/
waiter
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
#!/bin/bash
#waiter script (L) 8^12
MESSAGE="Wait"
WTIMEOUT=0
ITEM_ARR=0 #current item counter
CH_S[0]='-' #pseudographic items
CH_S[1]='/'
CH_S[2]='|'
CH_S[3]='\'
print_help()
{
echo "use waiter <time> [message]"
echo "<time> - wait time"
echo "[message] - optional text message"
}
#parameters check
if [ -z $1 ];then #if no parameters
print_help
exit 2
fi
#if help request
if [ $1 = "-h" ];then
print_help
exit 2
fi
if [ $1 = "--help" ];then
print_help
exit 2
fi
if [ -n "$2" ];then
MESSAGE=$2
fi
if (echo $1 | grep -E -q "^?[0-9]+$");then
WTIMEOUT=$1
else
echo "Not a number in first parameter <time>"
exit 1
fi
echo -n $MESSAGE" ("$WTIMEOUT" secounds): "
tput sc #save cursor position
while [ $WTIMEOUT -ge 0 ]; do
#print timeout and current pseudographic char
printf '%3s %s' $WTIMEOUT ${CH_S[ITEM_ARR]}
tput rc #restore cursor position
sleep 1
#decrease timeout and increase current item ctr.
let "WTIMEOUT=WTIMEOUT-1"
let "ITEM_ARR=ITEM_ARR+1"
if [ $ITEM_ARR -eq 4 ];then
#if items ctr > number of array items
#starting with 0 item
let "ITEM_ARR=0"
fi
done
#next message starting with new string
printf '\n'