reuse functions
This commit is contained in:
parent
653c9bd763
commit
6fb66d6e26
1 changed files with 4 additions and 35 deletions
|
@ -1,43 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
VERSION="$1"
|
VERSION="$1"
|
||||||
UNSUPPORTED_MSG="$2"
|
UNSUPPORTED_MSG="$2"
|
||||||
|
|
||||||
get_tmux_option() {
|
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||||
local option=$1
|
source "$CURRENT_DIR/scripts/shared_functions.sh"
|
||||||
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:
|
# this is used to get "clean" integer version number. Examples:
|
||||||
# `tmux 1.9` => `19`
|
# `tmux 1.9` => `19`
|
||||||
|
|
Loading…
Reference in a new issue