Skip to content

Commit f5ed764

Browse files
committed
Changing variable working way. Reducing 'get_tmux_option' uses. Adding auto-creating folders in logging path
1 parent b270611 commit f5ed764

File tree

6 files changed

+43
-58
lines changed

6 files changed

+43
-58
lines changed

logging.tmux

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

8+
89
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"
10+
tmux bind-key "$logging_key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
1111
}
1212

1313
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"
14+
tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
1615
}
1716

1817
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"
18+
tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
2119
}
2220

2321
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"
22+
tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
2623
}
2724

2825
main() {

scripts/capture_pane_helpers.sh

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
# Variables in this helper should be set in the file sourcing the helper.
2-
# Required variables:
3-
# - path_option & default_path
4-
# - name_option & default_name
5-
6-
get_path() {
7-
get_tmux_option "$path_option" "$default_path"
8-
}
9-
10-
# `tmux save-buffer` command does not perform interpolation, so we're doing it
11-
# "manually" with `display-message`
12-
get_filename() {
13-
local name_template=$(get_tmux_option "$name_option" "$default_name")
14-
tmux display-message -p "$name_template"
15-
}
16-
171
capture_pane() {
18-
local file="$(get_path)/$(get_filename)"
192
local capture_scope=$1
203
if [ $capture_scope == "History" ]; then
4+
local file=$(tmux display-message -p "$save_complete_history_full_filename")
5+
local path=$(tmux display-message -p "$save_complete_history_path")
6+
mkdir -p "$path"
217
local history_limit="$(tmux display-message -p -F "#{history_limit}")"
228
tmux capture-pane -J -S "-${history_limit}" -p > "$file"
239
elif [[ $capture_scope == "Screen capture" ]]; then
10+
local file=$(tmux display-message -p "$screen_capture_full_filename")
11+
local path=$(tmux display-message -p "$screen_capture_path")
12+
mkdir -p "$path"
2413
tmux capture-pane -J -p > "$file"
2514
else
2615
# error

scripts/save_complete_history.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ source "$CURRENT_DIR/variables.sh"
66
source "$CURRENT_DIR/shared.sh"
77
source "$CURRENT_DIR/capture_pane_helpers.sh"
88

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"
15-
169
main() {
1710
if supported_tmux_version_ok; then
1811
capture_pane "History"

scripts/screen_capture.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ source "$CURRENT_DIR/variables.sh"
66
source "$CURRENT_DIR/shared.sh"
77
source "$CURRENT_DIR/capture_pane_helpers.sh"
88

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"
15-
169
main() {
1710
if supported_tmux_version_ok; then
1811
capture_pane "Screen capture"

scripts/toggle_logging.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@ 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=$(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"
1815
}
1916

2017
stop_pipe_pane() {
2118
tmux pipe-pane
22-
display_message "Ended logging to $(get_filename)"
19+
display_message "Ended logging to $logging_full_filename"
2320
}
2421

2522
# 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)