1
1
#! /bin/bash
2
- source $SCRIPT_DIR /lib/discord_utils.sh
3
- source $SCRIPT_DIR /lib/minecraft_server_control.sh
4
- source $SCRIPT_DIR /lib/time_utils.sh
2
+ source ${ SCRIPT_DIR} /lib/discord_utils.sh
3
+ source ${ SCRIPT_DIR} /lib/minecraft_server_control.sh
4
+ source ${ SCRIPT_DIR} /lib/time_utils.sh
5
5
6
6
timer_text ()
7
7
{
8
- if [[ -z $tellraw_color ]] && [[ -z $tellraw_options ]]; then
8
+ if [[ -z ${ tellraw_color} ]] && [[ -z ${ tellraw_options} ]]; then
9
9
say_in_minecraft " $1 "
10
10
else
11
- tellraw_in_minecraft " $1 " " $tellraw_color " " $tellraw_options "
11
+ tellraw_in_minecraft " $1 " " ${ tellraw_color} " " ${ tellraw_options} "
12
12
fi
13
13
14
- if [[ ! -z $send_to_discord ]]; then
15
- send_message_to_discord " $1 " " $discord_username "
14
+ if [[ ! -z ${ send_to_discord} ]]; then
15
+ send_message_to_discord " $1 " " ${ discord_username} "
16
16
fi
17
17
}
18
18
@@ -23,64 +23,64 @@ run_progress_timer()
23
23
local task_function=$1
24
24
shift
25
25
26
- local start_message=" Starting $task_function ..."
27
- local progress_message=" $task_function in progress"
28
- local finish_message=" $task_function complete"
26
+ local start_message=" Starting ${ task_function} ..."
27
+ local progress_message=" ${ task_function} in progress"
28
+ local finish_message=" ${ task_function} complete"
29
29
30
30
local message_interval_in_seconds=1
31
31
local show_hours=false
32
32
33
33
while getopts " s:p:f:m:h:c:o:d:u:" OPTION
34
34
do
35
- case $OPTION in
36
- s) start_message=" $OPTARG "
35
+ case ${ OPTION} in
36
+ s) start_message=" ${ OPTARG} "
37
37
;;
38
- p) progress_message=" $OPTARG "
38
+ p) progress_message=" ${ OPTARG} "
39
39
;;
40
- f) finish_message=" $OPTARG "
40
+ f) finish_message=" ${ OPTARG} "
41
41
;;
42
- m) message_interval_in_seconds=$OPTARG
42
+ m) message_interval_in_seconds=${ OPTARG}
43
43
;;
44
- h) show_hours=$OPTARG
44
+ h) show_hours=${ OPTARG}
45
45
;;
46
- c) tellraw_color=" $OPTARG "
46
+ c) tellraw_color=" ${ OPTARG} "
47
47
;;
48
- o) tellraw_options=" $OPTARG "
48
+ o) tellraw_options=" ${ OPTARG} "
49
49
;;
50
- d) send_to_discord=$OPTARG
50
+ d) send_to_discord=${ OPTARG}
51
51
;;
52
- u) discord_username=" $OPTARG "
52
+ u) discord_username=" ${ OPTARG} "
53
53
;;
54
54
? ) printf " Usage: %s <task_function> [-s <start_message>] [-p <progress_message>] [-f <finish_message>] [-m <message_interval>] [-h <show_hours>] [-c <tellraw_color>] [-o <tellraw_options>] [-d <send_to_discord>] [-u <discord_username>]" $( basename $0 ) >&2
55
55
exit 2
56
56
;;
57
57
esac
58
58
done
59
- shift $(( $OPTIND - 1 ))
59
+ shift $(( ${ OPTIND} - 1 ))
60
60
61
61
local start_time=$( get_current_unix_time)
62
- local elapsed_time=$start_time
62
+ local elapsed_time=${ start_time}
63
63
local formatted_time=" "
64
64
65
- timer_text " $start_message "
65
+ timer_text " ${ start_message} "
66
66
67
- $task_function &
67
+ ${ task_function} &
68
68
background_pid=$!
69
69
70
- trap " kill $background_pid 2> /dev/null" EXIT
70
+ trap " kill ${ background_pid} 2> /dev/null" EXIT
71
71
72
- while kill -0 $background_pid 2> /dev/null
72
+ while kill -0 ${ background_pid} 2> /dev/null
73
73
do
74
74
sleep 1
75
- elapsed_time=$( get_elapsed_unix_time $start_time )
75
+ elapsed_time=$( get_elapsed_unix_time ${ start_time} )
76
76
77
- modulus=$(( $elapsed_time % $message_interval_in_seconds ))
78
- if [ " $modulus " -eq 0 ]; then
79
- formatted_time=$( unix_time_to_minutes_seconds $elapsed_time $ show_hours)
80
- timer_text " $progress_message : $formatted_time "
77
+ modulus=$(( ${ elapsed_time} % ${ message_interval_in_seconds} ))
78
+ if [ " ${ modulus} " -eq 0 ]; then
79
+ formatted_time=$( unix_time_to_minutes_seconds ${ elapsed_time} ${ show_hours} )
80
+ timer_text " ${ progress_message} : ${ formatted_time} "
81
81
fi
82
82
done
83
83
84
- formatted_time=$( unix_time_to_minutes_seconds $elapsed_time $ show_hours)
85
- timer_text " $finish_message : $formatted_time "
84
+ formatted_time=$( unix_time_to_minutes_seconds ${ elapsed_time} ${ show_hours} )
85
+ timer_text " ${ finish_message} : ${ formatted_time} "
86
86
}
0 commit comments