11#! /usr/bin/env bash
2-
2+ set +x
33CURRENT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
44
55source " $CURRENT_DIR /helpers.sh"
66source " $CURRENT_DIR /variables.sh"
77source " $CURRENT_DIR /shared.sh"
88
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 [ -n " $DEBUG " ] && [ -n " $log_path " ]; then
18+ message=" $@ "
19+ echo " $message " >> $log_path
20+ fi
21+ }
22+
923supported_tmux_version_ok () {
1024 " $CURRENT_DIR /check_tmux_version.sh" " $SUPPORTED_VERSION "
1125}
@@ -18,6 +32,14 @@ auto_save_not_disabled() {
1832 [ " $( get_interval) " -gt 0 ]
1933}
2034
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+
2143enough_time_since_last_run_passed () {
2244 local last_saved_timestamp=" $( get_tmux_option " $last_auto_save_option " " 0" ) "
2345 local interval_minutes=" $( get_interval) "
@@ -29,13 +51,29 @@ enough_time_since_last_run_passed() {
2951fetch_and_run_tmux_resurrect_save_script () {
3052 local resurrect_save_script_path=" $( get_tmux_option " $resurrect_save_path_option " " " ) "
3153 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
3361 set_last_save_timestamp
3462 fi
3563}
3664
3765main () {
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
3872 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
3977 fetch_and_run_tmux_resurrect_save_script
4078 fi
4179}
0 commit comments