Skip to content

Commit 7d3135b

Browse files
author
Bruno Sutic
committed
Refactoring logging script
1 parent 778da25 commit 7d3135b

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

logging.tmux

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ source "$CURRENT_DIR/scripts/variables.sh"
66
source "$CURRENT_DIR/scripts/shared.sh"
77

88
setup_logging_key_binding() {
9-
local key=$(get_tmux_option "$logging_key_option" "$default_logging_key")
9+
local key="$(get_tmux_option "$logging_key_option" "$default_logging_key")"
1010
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
1111
}
1212

13-
setup_pane_screenshot_key_binding() {
14-
local key=$(get_tmux_option "$pane_screen_capture_key_option" "$default_pane_screen_capture_key")
13+
setup_screen_capture_key_binding() {
14+
local key="$(get_tmux_option "$pane_screen_capture_key_option" "$default_pane_screen_capture_key")"
1515
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
1616
}
1717

18-
setup_scrollback_dump_key_binding() {
19-
local key=$(get_tmux_option "$save_complete_history_key_option" "$default_save_complete_history_key")
18+
setup_save_complete_history_key_binding() {
19+
local key="$(get_tmux_option "$save_complete_history_key_option" "$default_save_complete_history_key")"
2020
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
2121
}
2222

23-
setup_clear_scrollback_key_binding() {
24-
local key=$(get_tmux_option "$clear_history_key_option" "$default_clear_history_key")
23+
setup_clear_history_key_binding() {
24+
local key="$(get_tmux_option "$clear_history_key_option" "$default_clear_history_key")"
2525
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
2626
}
2727

2828
main() {
2929
setup_logging_key_binding
30-
setup_pane_screenshot_key_binding
31-
setup_scrollback_dump_key_binding
32-
setup_clear_scrollback_key_binding
30+
setup_screen_capture_key_binding
31+
setup_save_complete_history_key_binding
32+
setup_clear_history_key_binding
3333
}
3434
main

scripts/toggle_logging.sh

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,24 @@
22

33
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

5-
default_log_path="$HOME"
6-
default_log_name="tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
7-
8-
log_path_option="@logging-path"
9-
log_name_option="@logging-filename"
10-
115
source "$CURRENT_DIR/variables.sh"
126
source "$CURRENT_DIR/shared.sh"
137

14-
get_log_path() {
15-
get_tmux_option "$log_path_option" "$default_log_path"
16-
}
17-
18-
get_log_name() {
19-
get_tmux_option "$log_name_option" "$default_log_name"
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}"
2012
}
2113

2214
start_pipe_pane() {
23-
local file="$(get_log_path)/$(get_log_name)"
24-
"$CURRENT_DIR/start_logging.sh" "$file"
25-
display_message "Started logging to $file"
15+
local filename="$(get_filename)"
16+
"$CURRENT_DIR/start_logging.sh" "$filename"
17+
display_message "Started logging to $filename"
2618
}
2719

2820
stop_pipe_pane() {
29-
local file="$(get_log_path)/$(get_log_name)"
3021
tmux pipe-pane
31-
display_message "Ended logging to $file"
22+
display_message "Ended logging to $(get_filename)"
3223
}
3324

3425
# returns a string unique to current pane
@@ -38,16 +29,16 @@ pane_unique_id() {
3829

3930
# saving 'logging' 'not logging' status in a variable unique to pane
4031
set_logging_variable() {
41-
local value=$1
32+
local value="$1"
4233
local pane_unique_id="$(pane_unique_id)"
43-
tmux set-option -gq "@$pane_unique_id" "$value"
34+
tmux set-option -gq "@${pane_unique_id}" "$value"
4435
}
4536

4637
# this function checks if logging is happening for the current pane
4738
is_logging() {
4839
local pane_unique_id="$(pane_unique_id)"
49-
local current_pane_logging=$(get_tmux_option "@$pane_unique_id" "not logging")
50-
if [ $current_pane_logging == "logging" ]; then
40+
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")"
41+
if [ "$current_pane_logging" == "logging" ]; then
5142
return 0
5243
else
5344
return 1

scripts/variables.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ SUPPORTED_VERSION="1.9"
55
logging_key_option="@logging-key"
66
default_logging_key="P" # Shift-p
77

8-
pane_screen_capture_key_option="@pane-screen-capture-key"
8+
pane_screen_capture_key_option="@screen-capture-key"
99
default_pane_screen_capture_key="M-p" # Alt-p
1010

1111
save_complete_history_key_option="@save-complete-history-key"
1212
default_save_complete_history_key="M-P" # Alt-Shift-p
1313

14-
clear_history_key_option="@pane-clear-history-key"
14+
clear_history_key_option="@clear-history-key"
1515
default_clear_history_key="M-c" # Alt-c
16+
17+
# Logging options
18+
19+
logging_path_option="@logging-path"
20+
default_logging_path="$HOME"
21+
22+
logging_filename_option="@logging-filename"
23+
default_logging_filename="tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"

0 commit comments

Comments
 (0)