1
1
#! /usr/bin/env bash
2
-
2
+ set +x
3
3
CURRENT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
4
4
5
5
source " $CURRENT_DIR /helpers.sh"
6
6
source " $CURRENT_DIR /variables.sh"
7
7
source " $CURRENT_DIR /shared.sh"
8
8
9
+ DEBUG=$( get_tmux_option " $debug " )
10
+
11
+ get_log_path () {
12
+ get_tmux_option " $log_path " " $log_path_default "
13
+ }
14
+
15
+ log_message () {
16
+ log_path=$( get_log_path)
17
+ if [ " $DEBUG " == " 1" ] && [ -n " $log_path " ]; then
18
+ message=" $@ "
19
+ echo " $message " >> $log_path
20
+ fi
21
+ }
22
+
9
23
supported_tmux_version_ok () {
10
24
" $CURRENT_DIR /check_tmux_version.sh" " $SUPPORTED_VERSION "
11
25
}
@@ -18,6 +32,14 @@ auto_save_not_disabled() {
18
32
[ " $( get_interval) " -gt 0 ]
19
33
}
20
34
35
+ get_next_run () {
36
+ local last_saved_timestamp=" $( get_tmux_option " $last_auto_save_option " " 0" ) "
37
+ local interval_minutes=" $( get_interval) "
38
+ local interval_seconds=" $(( interval_minutes * 60 )) "
39
+ local next_run=" $(( last_saved_timestamp + $interval_seconds )) "
40
+ echo $next_run
41
+ }
42
+
21
43
enough_time_since_last_run_passed () {
22
44
local last_saved_timestamp=" $( get_tmux_option " $last_auto_save_option " " 0" ) "
23
45
local interval_minutes=" $( get_interval) "
@@ -29,13 +51,29 @@ enough_time_since_last_run_passed() {
29
51
fetch_and_run_tmux_resurrect_save_script () {
30
52
local resurrect_save_script_path=" $( get_tmux_option " $resurrect_save_path_option " " " ) "
31
53
if [ -n " $resurrect_save_script_path " ]; then
32
- " $resurrect_save_script_path " " quiet" > /dev/null 2>&1 &
54
+ if [ -n " $DEBUG " ]; then
55
+ local log_path=$( get_log_path)
56
+ log_message " Calling $resurrect_save_script_path "
57
+ " $resurrect_save_script_path " >> $log_path 2>&1 &
58
+ else
59
+ " $resurrect_save_script_path " " quiet" > /dev/null 2>&1 &
60
+ fi
33
61
set_last_save_timestamp
34
62
fi
35
63
}
36
64
37
65
main () {
66
+ if [ -n " $DEBUG " ]; then
67
+ TS_NEXT=$( get_next_run)
68
+ TIME_NEXT=$( date -d \@ " $TS_NEXT " +" %Y-%m-%d at %H:%M:%S" )
69
+ MSG=" Next save on $TIME_NEXT "
70
+ log_message " $( date +' %Y-%m-%d %H:%M:%S' ) : $MSG "
71
+ fi
38
72
if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then
73
+ if [ -n " $DEBUG " ]; then
74
+ log_message " Actual run on $( date) "
75
+ echo " Saved on $( date +' %Y-%m-%d@%H:%M:%S' ) "
76
+ fi
39
77
fetch_and_run_tmux_resurrect_save_script
40
78
fi
41
79
}
0 commit comments