2014-08-29 16:59:14 +00:00
|
|
|
default_resurrect_dir="$HOME/.tmux/resurrect"
|
|
|
|
resurrect_dir_option="@resurrect-dir"
|
2014-08-27 11:12:32 +00:00
|
|
|
|
2014-08-26 13:47:31 +00:00
|
|
|
SUPPORTED_VERSION="1.9"
|
|
|
|
|
2015-02-09 01:11:35 +00:00
|
|
|
d=$'\t'
|
|
|
|
|
2014-08-26 13:31:47 +00:00
|
|
|
# helper functions
|
2014-08-25 20:29:03 +00:00
|
|
|
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"
|
|
|
|
}
|
2014-08-26 13:31:47 +00:00
|
|
|
|
2014-08-26 13:47:31 +00:00
|
|
|
|
|
|
|
supported_tmux_version_ok() {
|
|
|
|
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
|
|
|
|
}
|
|
|
|
|
2014-08-28 21:39:53 +00:00
|
|
|
remove_first_char() {
|
|
|
|
echo "$1" | cut -c2-
|
|
|
|
}
|
|
|
|
|
2014-10-17 20:33:29 +00:00
|
|
|
save_bash_history_option_on() {
|
|
|
|
local option="$(get_tmux_option "$bash_history_option" "off")"
|
|
|
|
[ "$option" == "on" ]
|
|
|
|
}
|
|
|
|
|
2015-02-09 01:11:35 +00:00
|
|
|
get_grouped_sessions() {
|
|
|
|
local grouped_sessions_dump="$1"
|
2015-02-09 15:34:24 +00:00
|
|
|
export GROUPED_SESSIONS="${d}$(echo "$grouped_sessions_dump" | cut -f2 -d"$d" | tr "\\n" "$d")"
|
2015-02-09 01:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
is_session_grouped() {
|
|
|
|
local session_name="$1"
|
|
|
|
[[ "$GROUPED_SESSIONS" == *"${d}${session_name}${d}"* ]]
|
|
|
|
}
|
|
|
|
|
2015-02-12 11:46:48 +00:00
|
|
|
restore_zoomed_windows() {
|
|
|
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
|
|
|
|
while IFS=$d read session_name window_number; do
|
|
|
|
tmux resize-pane -t "${session_name}:${window_number}" -Z
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-08-26 13:47:31 +00:00
|
|
|
# path helpers
|
|
|
|
|
2014-08-29 16:59:14 +00:00
|
|
|
resurrect_dir() {
|
|
|
|
echo $(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")
|
2014-08-26 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 16:59:14 +00:00
|
|
|
resurrect_file_path() {
|
2014-08-26 13:31:47 +00:00
|
|
|
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
|
2014-08-29 16:59:14 +00:00
|
|
|
echo "$(resurrect_dir)/tmux_resurrect_${timestamp}.txt"
|
2014-08-26 13:31:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 16:59:14 +00:00
|
|
|
last_resurrect_file() {
|
|
|
|
echo "$(resurrect_dir)/last"
|
2014-08-26 13:31:47 +00:00
|
|
|
}
|
2014-10-12 22:47:44 +00:00
|
|
|
|
|
|
|
resurrect_history_file() {
|
|
|
|
local pane_id="$1"
|
|
|
|
echo "$(resurrect_dir)/bash_history-${pane_id}"
|
|
|
|
}
|