Require tmux 1.9 to use the plugin

This commit is contained in:
Bruno Sutic 2015-03-14 22:12:53 +01:00
parent 1e5e8d0532
commit dc6da8fdf8
No known key found for this signature in database
GPG key ID: 66D96E4F2F7EF26C
9 changed files with 111 additions and 12 deletions

View file

@ -3,6 +3,7 @@
### master
- update readme
- extract default keys and key options to `variables.sh` file
- require tmux version 1.9 or greater to use the plugin
### v1.0.0, 2014-11-09
- improve `capture-pane`. It is now piped directly to the target file.

View file

@ -2,8 +2,8 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/shared.sh"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/scripts/shared.sh"
setup_pipe_pane_key_binding() {
local key=$(get_tmux_option "$pipe_pane_key_option" "$default_pipe_pane_key")

78
scripts/check_tmux_version.sh Executable file
View file

@ -0,0 +1,78 @@
#!/usr/bin/env bash
VERSION="$1"
UNSUPPORTED_MSG="$2"
get_tmux_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
local message="$1"
# display_duration defaults to 5 seconds, if not passed as an argument
if [ "$#" -eq 2 ]; then
local display_duration="$2"
else
local display_duration="5000"
fi
# saves user-set 'display-time' option
local saved_display_time=$(get_tmux_option "display-time" "750")
# sets message display time to 5 seconds
tmux set-option -gq display-time "$display_duration"
# displays message
tmux display-message "$message"
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}
# this is used to get "clean" integer version number. Examples:
# `tmux 1.9` => `19`
# `1.9a` => `19`
get_digits_from_string() {
local string="$1"
local only_digits="$(echo "$string" | tr -dC '[:digit:]')"
echo "$only_digits"
}
tmux_version_int() {
local tmux_version_string=$(tmux -V)
echo "$(get_digits_from_string "$tmux_version_string")"
}
unsupported_version_message() {
if [ -n "$UNSUPPORTED_MSG" ]; then
echo "$UNSUPPORTED_MSG"
else
echo "Error, Tmux version unsupported! Please install Tmux version $VERSION or greater!"
fi
}
exit_if_unsupported_version() {
local current_version="$1"
local supported_version="$2"
if [ "$current_version" -lt "$supported_version" ]; then
display_message "$(unsupported_version_message)"
exit 1
fi
}
main() {
local supported_version_int="$(get_digits_from_string "$VERSION")"
local current_version_int="$(tmux_version_int)"
exit_if_unsupported_version "$current_version_int" "$supported_version_int"
}
main

View file

@ -39,3 +39,7 @@ remove_empty_lines_from_end_of_file() {
local temp=$(cat $file)
printf '%s\n' "$temp" > "$file"
}
supported_tmux_version_ok() {
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
}

View file

@ -9,10 +9,13 @@ default_name="tmux-screen-capture-#{session_name}-#{window_index}-#{pane_index}-
path_option="@screenshot_path"
name_option="@screenshot_filename"
source $CURRENT_DIR/shared.sh
source $CURRENT_DIR/capture_pane_helpers.sh
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
source "$CURRENT_DIR/capture_pane_helpers.sh"
main() {
capture_pane "Screen capture"
if supported_tmux_version_ok; then
capture_pane "Screen capture"
fi
}
main

View file

@ -8,7 +8,8 @@ default_log_name="tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M
log_path_option="@pipe_pane_path"
log_name_option="@pipe_pane_filename"
source $CURRENT_DIR/shared.sh
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
get_log_path() {
get_tmux_option "$log_path_option" "$default_log_path"
@ -65,6 +66,8 @@ toggle_pipe_pane() {
}
main() {
toggle_pipe_pane
if supported_tmux_version_ok; then
toggle_pipe_pane
fi
}
main

View file

@ -2,10 +2,13 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/shared.sh
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
main() {
tmux clear-history
display_message "Pane history cleared!"
if supported_tmux_version_ok; then
tmux clear-history
display_message "Pane history cleared!"
fi
}
main

View file

@ -9,10 +9,13 @@ default_name="tmux-history-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT
path_option="@scrollback_dump_path"
name_option="@scrollback_dump_filename"
source $CURRENT_DIR/shared.sh
source $CURRENT_DIR/capture_pane_helpers.sh
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
source "$CURRENT_DIR/capture_pane_helpers.sh"
main() {
capture_pane "History"
if supported_tmux_version_ok; then
capture_pane "History"
fi
}
main

View file

@ -1,3 +1,7 @@
SUPPORTED_VERSION="1.9"
# Key binding options and defaults
pipe_pane_key_option="@pipe-pane-key"
default_pipe_pane_key="P" # Shift-p