Skip to content

Commit dc6da8f

Browse files
author
Bruno Sutic
committed
Require tmux 1.9 to use the plugin
1 parent 1e5e8d0 commit dc6da8f

File tree

9 files changed

+111
-12
lines changed

9 files changed

+111
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### master
44
- update readme
55
- extract default keys and key options to `variables.sh` file
6+
- require tmux version 1.9 or greater to use the plugin
67

78
### v1.0.0, 2014-11-09
89
- improve `capture-pane`. It is now piped directly to the target file.

logging.tmux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

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

5-
source "$CURRENT_DIR/scripts/shared.sh"
65
source "$CURRENT_DIR/scripts/variables.sh"
6+
source "$CURRENT_DIR/scripts/shared.sh"
77

88
setup_pipe_pane_key_binding() {
99
local key=$(get_tmux_option "$pipe_pane_key_option" "$default_pipe_pane_key")

scripts/check_tmux_version.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
VERSION="$1"
4+
UNSUPPORTED_MSG="$2"
5+
6+
get_tmux_option() {
7+
local option=$1
8+
local default_value=$2
9+
local option_value=$(tmux show-option -gqv "$option")
10+
if [ -z "$option_value" ]; then
11+
echo "$default_value"
12+
else
13+
echo "$option_value"
14+
fi
15+
}
16+
17+
# Ensures a message is displayed for 5 seconds in tmux prompt.
18+
# Does not override the 'display-time' tmux option.
19+
display_message() {
20+
local message="$1"
21+
22+
# display_duration defaults to 5 seconds, if not passed as an argument
23+
if [ "$#" -eq 2 ]; then
24+
local display_duration="$2"
25+
else
26+
local display_duration="5000"
27+
fi
28+
29+
# saves user-set 'display-time' option
30+
local saved_display_time=$(get_tmux_option "display-time" "750")
31+
32+
# sets message display time to 5 seconds
33+
tmux set-option -gq display-time "$display_duration"
34+
35+
# displays message
36+
tmux display-message "$message"
37+
38+
# restores original 'display-time' value
39+
tmux set-option -gq display-time "$saved_display_time"
40+
}
41+
42+
# this is used to get "clean" integer version number. Examples:
43+
# `tmux 1.9` => `19`
44+
# `1.9a` => `19`
45+
get_digits_from_string() {
46+
local string="$1"
47+
local only_digits="$(echo "$string" | tr -dC '[:digit:]')"
48+
echo "$only_digits"
49+
}
50+
51+
tmux_version_int() {
52+
local tmux_version_string=$(tmux -V)
53+
echo "$(get_digits_from_string "$tmux_version_string")"
54+
}
55+
56+
unsupported_version_message() {
57+
if [ -n "$UNSUPPORTED_MSG" ]; then
58+
echo "$UNSUPPORTED_MSG"
59+
else
60+
echo "Error, Tmux version unsupported! Please install Tmux version $VERSION or greater!"
61+
fi
62+
}
63+
64+
exit_if_unsupported_version() {
65+
local current_version="$1"
66+
local supported_version="$2"
67+
if [ "$current_version" -lt "$supported_version" ]; then
68+
display_message "$(unsupported_version_message)"
69+
exit 1
70+
fi
71+
}
72+
73+
main() {
74+
local supported_version_int="$(get_digits_from_string "$VERSION")"
75+
local current_version_int="$(tmux_version_int)"
76+
exit_if_unsupported_version "$current_version_int" "$supported_version_int"
77+
}
78+
main

scripts/shared.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ remove_empty_lines_from_end_of_file() {
3939
local temp=$(cat $file)
4040
printf '%s\n' "$temp" > "$file"
4141
}
42+
43+
supported_tmux_version_ok() {
44+
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
45+
}

scripts/tmux_pane_screenshot.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ default_name="tmux-screen-capture-#{session_name}-#{window_index}-#{pane_index}-
99
path_option="@screenshot_path"
1010
name_option="@screenshot_filename"
1111

12-
source $CURRENT_DIR/shared.sh
13-
source $CURRENT_DIR/capture_pane_helpers.sh
12+
source "$CURRENT_DIR/variables.sh"
13+
source "$CURRENT_DIR/shared.sh"
14+
source "$CURRENT_DIR/capture_pane_helpers.sh"
1415

1516
main() {
16-
capture_pane "Screen capture"
17+
if supported_tmux_version_ok; then
18+
capture_pane "Screen capture"
19+
fi
1720
}
1821
main

scripts/tmux_proper_pipe_pane.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ default_log_name="tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M
88
log_path_option="@pipe_pane_path"
99
log_name_option="@pipe_pane_filename"
1010

11-
source $CURRENT_DIR/shared.sh
11+
source "$CURRENT_DIR/variables.sh"
12+
source "$CURRENT_DIR/shared.sh"
1213

1314
get_log_path() {
1415
get_tmux_option "$log_path_option" "$default_log_path"
@@ -65,6 +66,8 @@ toggle_pipe_pane() {
6566
}
6667

6768
main() {
68-
toggle_pipe_pane
69+
if supported_tmux_version_ok; then
70+
toggle_pipe_pane
71+
fi
6972
}
7073
main

scripts/tmux_scrollback_clear.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

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

5-
source $CURRENT_DIR/shared.sh
5+
source "$CURRENT_DIR/variables.sh"
6+
source "$CURRENT_DIR/shared.sh"
67

78
main() {
8-
tmux clear-history
9-
display_message "Pane history cleared!"
9+
if supported_tmux_version_ok; then
10+
tmux clear-history
11+
display_message "Pane history cleared!"
12+
fi
1013
}
1114
main

scripts/tmux_scrollback_dump.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ default_name="tmux-history-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT
99
path_option="@scrollback_dump_path"
1010
name_option="@scrollback_dump_filename"
1111

12-
source $CURRENT_DIR/shared.sh
13-
source $CURRENT_DIR/capture_pane_helpers.sh
12+
source "$CURRENT_DIR/variables.sh"
13+
source "$CURRENT_DIR/shared.sh"
14+
source "$CURRENT_DIR/capture_pane_helpers.sh"
1415

1516
main() {
16-
capture_pane "History"
17+
if supported_tmux_version_ok; then
18+
capture_pane "History"
19+
fi
1720
}
1821
main

scripts/variables.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
SUPPORTED_VERSION="1.9"
2+
3+
# Key binding options and defaults
4+
15
pipe_pane_key_option="@pipe-pane-key"
26
default_pipe_pane_key="P" # Shift-p
37

0 commit comments

Comments
 (0)