Skip to content

Commit f79e5ed

Browse files
authored
Merge pull request #21 from selfuryon/master
Auto-creating folders in logging path #2
2 parents b270611 + 3059d52 commit f79e5ed

File tree

7 files changed

+54
-91
lines changed

7 files changed

+54
-91
lines changed

logging.tmux

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,12 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55
source "$CURRENT_DIR/scripts/variables.sh"
66
source "$CURRENT_DIR/scripts/shared.sh"
77

8-
setup_logging_key_binding() {
9-
local key="$(get_tmux_option "$logging_key_option" "$default_logging_key")"
10-
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
11-
}
12-
13-
setup_screen_capture_key_binding() {
14-
local key="$(get_tmux_option "$pane_screen_capture_key_option" "$default_pane_screen_capture_key")"
15-
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
16-
}
17-
18-
setup_save_complete_history_key_binding() {
19-
local key="$(get_tmux_option "$save_complete_history_key_option" "$default_save_complete_history_key")"
20-
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
21-
}
22-
23-
setup_clear_history_key_binding() {
24-
local key="$(get_tmux_option "$clear_history_key_option" "$default_clear_history_key")"
25-
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
26-
}
278

289
main() {
29-
setup_logging_key_binding
30-
setup_screen_capture_key_binding
31-
setup_save_complete_history_key_binding
32-
setup_clear_history_key_binding
10+
tmux bind-key "$logging_key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
11+
tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
12+
tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
13+
tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
3314
}
15+
3416
main

scripts/capture_pane_helpers.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

scripts/save_complete_history.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
source "$CURRENT_DIR/variables.sh"
66
source "$CURRENT_DIR/shared.sh"
7-
source "$CURRENT_DIR/capture_pane_helpers.sh"
8-
9-
# Functions defined in capture_pane_helpers are customized via below variables.
10-
default_path="$default_save_complete_history_path"
11-
default_name="$default_save_complete_history_filename"
12-
13-
path_option="$save_complete_history_path_option"
14-
name_option="$save_complete_history_filename_option"
157

168
main() {
179
if supported_tmux_version_ok; then
18-
capture_pane "History"
10+
local file=$(expand_tmux_format_path "${save_complete_history_full_filename}")
11+
local history_limit="$(tmux display-message -p -F "#{history_limit}")"
12+
tmux capture-pane -J -S "-${history_limit}" -p > "${file}"
13+
remove_empty_lines_from_end_of_file "${file}"
14+
display_message "History saved to ${file}"
1915
fi
2016
}
2117
main

scripts/screen_capture.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
source "$CURRENT_DIR/variables.sh"
66
source "$CURRENT_DIR/shared.sh"
7-
source "$CURRENT_DIR/capture_pane_helpers.sh"
8-
9-
# Functions defined in capture_pane_helpers are customized via below variables.
10-
default_path="$default_screen_capture_path"
11-
default_name="$default_screen_capture_filename"
12-
13-
path_option="$screen_capture_path_option"
14-
name_option="$screen_capture_filename_option"
157

168
main() {
179
if supported_tmux_version_ok; then
18-
capture_pane "Screen capture"
10+
local file=$(expand_tmux_format_path "${screen_capture_full_filename}")
11+
tmux capture-pane -J -p > "${file}"
12+
remove_empty_lines_from_end_of_file "${file}"
13+
display_message "Screen capture saved to ${file}"
1914
fi
2015
}
2116
main

scripts/shared.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ remove_empty_lines_from_end_of_file() {
4343
supported_tmux_version_ok() {
4444
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
4545
}
46+
47+
# Checking full path to logfile and expanding tmux format in normal path
48+
# As example: expand %Y-%m-%d to current date
49+
expand_tmux_format_path() {
50+
local tmux_format_path=$1
51+
local full_path=$(tmux display-message -p "${tmux_format_path}")
52+
local full_directory_path=${full_path%/*}
53+
mkdir -p "${full_directory_path}"
54+
echo "${full_path}"
55+
}

scripts/toggle_logging.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55
source "$CURRENT_DIR/variables.sh"
66
source "$CURRENT_DIR/shared.sh"
77

8-
get_filename() {
9-
local logging_path="$(get_tmux_option "$logging_path_option" "$default_logging_path")"
10-
local logging_filename="$(get_tmux_option "$logging_filename_option" "$default_logging_filename")"
11-
echo "${logging_path}/${logging_filename}"
12-
}
138

149
start_pipe_pane() {
15-
local filename="$(get_filename)"
16-
"$CURRENT_DIR/start_logging.sh" "$filename"
17-
display_message "Started logging to $filename"
10+
local file=$(expand_tmux_format_path "${logging_full_filename}")
11+
"$CURRENT_DIR/start_logging.sh" "${file}"
12+
display_message "Started logging to ${logging_full_filename}"
1813
}
1914

2015
stop_pipe_pane() {
2116
tmux pipe-pane
22-
display_message "Ended logging to $(get_filename)"
17+
display_message "Ended logging to $logging_full_filename"
2318
}
2419

2520
# returns a string unique to current pane

scripts/variables.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,54 @@ SUPPORTED_VERSION="1.9"
22

33
# Key binding options and defaults
44

5-
logging_key_option="@logging-key"
65
default_logging_key="P" # Shift-p
6+
logging_key=$(tmux show-option -gqv "@logging_key")
7+
logging_key=${logging_key:-$default_logging_key}
78

8-
pane_screen_capture_key_option="@screen-capture-key"
99
default_pane_screen_capture_key="M-p" # Alt-p
10+
pane_screen_capture_key=$(tmux show-option -gqv "@screen-capture-key")
11+
pane_screen_capture_key=${pane_screen_capture_key:-$default_pane_screen_capture_key}
1012

11-
save_complete_history_key_option="@save-complete-history-key"
1213
default_save_complete_history_key="M-P" # Alt-Shift-p
14+
save_complete_history_key=$(tmux show-option -gqv "@save-complete-history-key")
15+
save_complete_history_key=${save_complete_history_key:-$default_save_complete_history_key}
1316

14-
clear_history_key_option="@clear-history-key"
1517
default_clear_history_key="M-c" # Alt-c
18+
clear_history_key=$(tmux show-option -gqv "@clear-history-key")
19+
clear_history_key=${clear_history_key:-$default_clear_history_key}
1620

1721
# General options
1822
filename_suffix="#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
1923

2024
# Logging options
21-
logging_path_option="@logging-path"
2225
default_logging_path="$HOME"
26+
logging_path=$(tmux show-option -gqv "@logging-path")
27+
logging_path=${logging_path:-$default_clear_history_key}
2328

24-
logging_filename_option="@logging-filename"
2529
default_logging_filename="tmux-${filename_suffix}"
30+
logging_filename=$(tmux show-option -gqv "@logging-filename")
31+
logging_filename=${logging_filename:-$default_logging_filename}
32+
33+
logging_full_filename="${logging_path}/${logging_filename}"
2634

2735
# Screen capture options
28-
screen_capture_path_option="@screen-capture-path"
2936
default_screen_capture_path="$HOME"
37+
screen_capture_path=$(tmux show-option -gqv "@screen-capture-path")
38+
screen_capture_path=${screen_capture_path:-$default_screen_capture_path}
3039

31-
screen_capture_filename_option="@screen-capture-filename"
3240
default_screen_capture_filename="tmux-screen-capture-${filename_suffix}"
41+
screen_capture_filename=$(tmux show-option -gqv "@screen-capture-filename")
42+
screen_capture_filename=${screen_capture_filename:-$default_screen_capture_filename}
43+
44+
screen_capture_full_filename="${screen_capture_path}/${screen_capture_filename}"
3345

3446
# Save complete history options
35-
save_complete_history_path_option="@save-complete-history-path"
3647
default_save_complete_history_path="$HOME"
48+
save_complete_history_path=$(tmux show-option -gqv "@save-complete-history-path")
49+
save_complete_history_path=${save_complete_history_path:-$default_save_complete_history_path}
3750

38-
save_complete_history_filename_option="@save-complete-history-filename"
3951
default_save_complete_history_filename="tmux-history-${filename_suffix}"
52+
save_complete_history_filename=$(tmux show-option -gqv "@save-complete-history-filename")
53+
save_complete_history_filename=${save_complete_history_filename:-$default_save_complete_history_filename}
54+
55+
save_complete_history_full_filename="${save_complete_history_path}/${save_complete_history_filename}"

0 commit comments

Comments
 (0)