-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_source
More file actions
46 lines (41 loc) · 1.07 KB
/
task_source
File metadata and controls
46 lines (41 loc) · 1.07 KB
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
# vim: ft=sh
export logFile=${logFile:-/dev/null}
function waitProgress()
{
local pid=$!
local msg=$1
local delay=0.25
local str=("/" "-" "\\" "|")
local str_l=${#str[@]}
local str_color=(1 2 3 4 5 6 7)
local str_color_l=${#str_color[@]}
local index=0
local index_c=0
local _FAIL="[$(tput setaf 1)-$(tput sgr0)]"
local _SUCCESS="[$(tput setaf 2)+$(tput sgr0)]"
local _NOTE="[*]"
[[ -z $msg ]] && {
msg="Waiting..."
}
if [[ -t 1 ]]; then
# produces spinner indicator
while kill -0 $pid &>/dev/null; do
echo -ne "\r[$(tput setaf $index_c)${str[$index]}$(tput sgr0)] $msg "
sleep $delay
index=$(( $(( $index + 1 )) % $str_l ))
index_c=$(( $(( $index_c + 1 )) % $str_color_l ))
done
else
# or a simpler indicator
echo -en "\r[...] $msg"
fi
# block
if wait $pid ; then
ret=$?
echo -en "\r$_SUCCESS $msg \n"
else
ret=$?
echo -en "\r$_FAIL $msg \n"
fi
return $ret
}