@@ -16,52 +16,52 @@ module_options+=(
16
16
function set_checkpoint() {
17
17
case " $1 " in
18
18
help)
19
- echo " Usage: set_checkpoint <start|stop|mark|show> [description] [show]"
20
- echo " Commands:"
21
- echo " start Start the timer."
22
- echo " stop Stop the timer."
23
- echo " mark [description] [time] Mark a checkpoint with an optional description and an optional flag to show the output."
24
- echo " show Show the total elapsed time and checkpoints."
19
+ echo " Usage: set_checkpoint <start|stop|mark|show> [description] [show]"
20
+ echo " Commands:"
21
+ echo " start Start the timer."
22
+ echo " stop Stop the timer."
23
+ echo " mark [description] [time] Mark a checkpoint with an optional description and an optional flag to show the output."
24
+ echo " show Show the total elapsed time and checkpoints."
25
25
;;
26
26
start)
27
- set_checkpoint_START=$( date +%s)
28
- set_checkpoint_CHECKPOINTS=()
29
- set_checkpoint_DESCRIPTIONS=()
30
- set_checkpoint_PREV=$set_checkpoint_START
27
+ set_checkpoint_START=$( date +%s)
28
+ set_checkpoint_CHECKPOINTS=()
29
+ set_checkpoint_DESCRIPTIONS=()
30
+ set_checkpoint_PREV=$set_checkpoint_START
31
31
;;
32
32
stop)
33
- set_checkpoint_STOP=$( date +%s)
33
+ set_checkpoint_STOP=$( date +%s)
34
34
;;
35
35
mark)
36
- local checkpoint_time= $( date +%s )
37
- local checkpoint_duration =$(( checkpoint_time - set_checkpoint_PREV ) )
38
- set_checkpoint_PREV= $ checkpoint_time
39
- set_checkpoint_CHECKPOINTS+=( $checkpoint_time )
40
- set_checkpoint_DESCRIPTIONS +=(" $2 " )
41
- local count= ${ # set_checkpoint_DESCRIPTIONS[@]}
42
- if [[ " $3 " == " true " && $UXMODE == " true " ]] ; then
43
- printf " %-30s %10d seconds\n" " $2 : " " ${checkpoint_duration} "
44
- fi
36
+ if [[ " $UXMODE " == " true " ]] ; then
37
+ local checkpoint_time =$( date +%s )
38
+ local checkpoint_duration= $(( checkpoint_time - set_checkpoint_PREV ))
39
+ set_checkpoint_PREV= $checkpoint_time
40
+ set_checkpoint_CHECKPOINTS +=($checkpoint_time )
41
+ set_checkpoint_DESCRIPTIONS+=( " $2 " )
42
+ local count= ${ # set_checkpoint_DESCRIPTIONS[@]}
43
+ printf " %-30s %10d seconds\n" " $2 " " ${checkpoint_duration} "
44
+ fi
45
45
;;
46
46
show)
47
- if [[ -n " $set_checkpoint_START " && -n " $set_checkpoint_STOP " ]]; then
48
- set_checkpoint_DURATION=$(( set_checkpoint_STOP - set_checkpoint_START))
49
- printf " %-30s: %d seconds\n" " Total elapsed time" " ${set_checkpoint_DURATION} "
47
+ if [[ -n " $set_checkpoint_START " && -n " $set_checkpoint_STOP " ]]; then
48
+ set_checkpoint_DURATION=$(( set_checkpoint_STOP - set_checkpoint_START))
49
+ printf " %-30s: %d seconds\n" " Total elapsed time" " ${set_checkpoint_DURATION} "
50
50
51
- local previous_time=$set_checkpoint_START
52
- for i in " ${! set_checkpoint_CHECKPOINTS[@]} " ; do
53
- local checkpoint_time=${set_checkpoint_CHECKPOINTS[$i]}
54
- local checkpoint_duration=$(( checkpoint_time - previous_time))
55
- local description=${set_checkpoint_DESCRIPTIONS[$i]}
56
- printf " %-30s: %d seconds\n" " ${description:- Checkpoint $((i+1))} " " ${checkpoint_duration} "
57
- previous_time=$checkpoint_time
58
- done
59
- else
60
- echo " Timer has not been started and stopped properly."
61
- fi
51
+ local previous_time=$set_checkpoint_START
52
+ for i in " ${! set_checkpoint_CHECKPOINTS[@]} " ; do
53
+ local checkpoint_time=${set_checkpoint_CHECKPOINTS[$i]}
54
+ local checkpoint_duration=$(( checkpoint_time - previous_time))
55
+ local description=${set_checkpoint_DESCRIPTIONS[$i]}
56
+ printf " %-30s: %d seconds\n" " ${description:- Checkpoint $((i+1))} " " ${checkpoint_duration} "
57
+ previous_time=$checkpoint_time
58
+ done
59
+ else
60
+ echo " Timer has not been started and stopped properly."
61
+ fi
62
62
;;
63
63
* )
64
- echo " Usage: set_checkpoint <start|stop|mark|show> [description]"
64
+ echo " Usage: set_checkpoint <start|stop|mark|show> [description]"
65
65
;;
66
66
esac
67
67
}
0 commit comments