Skip to content

Commit 82d8ad5

Browse files
author
Sergei Gerasenko
committed
Add infrastructure for debugging.
1 parent fc73e09 commit 82d8ad5

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Diff for: scripts/continuum_save.sh

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#!/usr/bin/env bash
2-
2+
set +x
33
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
source "$CURRENT_DIR/helpers.sh"
66
source "$CURRENT_DIR/variables.sh"
77
source "$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 [ "$DEBUG" == "1" ] && [ -n "$log_path" ]; then
18+
message="$@"
19+
echo "$message" >> $log_path
20+
fi
21+
}
22+
923
supported_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+
2143
enough_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() {
2951
fetch_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

3765
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
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
}

Diff for: scripts/variables.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
SUPPORTED_VERSION="1.9"
22

3+
log_path="@continuum-log-path"
4+
log_path_default="${HOME}/tmux-continuum.log"
5+
debug="@continuum-debug"
6+
37
# these tmux options contain paths to tmux resurrect save and restore scripts
48
resurrect_save_path_option="@resurrect-save-script-path"
59
resurrect_restore_path_option="@resurrect-restore-script-path"

0 commit comments

Comments
 (0)