Skip to content

Commit 3059d52

Browse files
committed
Refactoring code based on #21 PR comments
1 parent f5ed764 commit 3059d52

File tree

6 files changed

+23
-45
lines changed

6 files changed

+23
-45
lines changed

logging.tmux

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,11 @@ source "$CURRENT_DIR/scripts/variables.sh"
66
source "$CURRENT_DIR/scripts/shared.sh"
77

88

9-
setup_logging_key_binding() {
9+
main() {
1010
tmux bind-key "$logging_key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
11-
}
12-
13-
setup_screen_capture_key_binding() {
1411
tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
15-
}
16-
17-
setup_save_complete_history_key_binding() {
1812
tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
19-
}
20-
21-
setup_clear_history_key_binding() {
2213
tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
2314
}
2415

25-
main() {
26-
setup_logging_key_binding
27-
setup_screen_capture_key_binding
28-
setup_save_complete_history_key_binding
29-
setup_clear_history_key_binding
30-
}
3116
main

scripts/capture_pane_helpers.sh

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

scripts/save_complete_history.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +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"
87

98
main() {
109
if supported_tmux_version_ok; then
11-
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}"
1215
fi
1316
}
1417
main

scripts/screen_capture.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +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"
87

98
main() {
109
if supported_tmux_version_ok; then
11-
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}"
1214
fi
1315
}
1416
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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ source "$CURRENT_DIR/shared.sh"
77

88

99
start_pipe_pane() {
10-
local file=$(tmux display-message -p "$logging_full_filename")
11-
local path=$(tmux display-message -p "$logging_path")
12-
mkdir -p "$path"
13-
"$CURRENT_DIR/start_logging.sh" "$file"
14-
display_message "Started logging to $logging_full_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}"
1513
}
1614

1715
stop_pipe_pane() {

0 commit comments

Comments
 (0)