tmux-continuum/resurrect_auto.tmux

57 lines
1.4 KiB
Plaintext
Raw Normal View History

2015-02-11 14:43:37 +00:00
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2015-02-12 14:45:16 +00:00
source "$CURRENT_DIR/scripts/helpers.sh"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/scripts/shared.sh"
2015-02-11 14:43:37 +00:00
save_command_interpolation="#($CURRENT_DIR/scripts/resurrect_auto_save.sh)"
2015-02-12 14:52:10 +00:00
supported_tmux_version_ok() {
$CURRENT_DIR/scripts/check_tmux_version.sh "$SUPPORTED_VERSION"
}
handle_tmux_automatic_start() {
$CURRENT_DIR/scripts/handle_tmux_automatic_start.sh
}
2015-02-19 23:53:42 +00:00
delay_saving_environment_on_first_plugin_load() {
if [ -z "$(get_tmux_option "$last_auto_save_option" "")" ]; then
# last save option not set, this is first time plugin load
set_last_save_timestamp
fi
}
2015-02-11 14:43:37 +00:00
add_resurrect_save_interpolation() {
local status_right_value="$(get_tmux_option "status-right" "")"
local new_value="${save_command_interpolation}${status_right_value}"
set_tmux_option "status-right" "$new_value"
}
2015-02-15 13:36:06 +00:00
# on tmux server start, when tmux.conf is sourced there are no sessions and
# `tmux has` reports 1
just_started_tmux_server() {
tmux has
[ $? -eq 1 ]
}
start_auto_restore_in_background() {
$CURRENT_DIR/scripts/resurrect_auto_restore.sh &
}
2015-02-11 14:43:37 +00:00
main() {
2015-02-12 02:37:34 +00:00
if supported_tmux_version_ok; then
handle_tmux_automatic_start
2015-02-19 23:53:42 +00:00
# give user a chance to restore previously saved session
delay_saving_environment_on_first_plugin_load
2015-02-12 02:37:34 +00:00
add_resurrect_save_interpolation
2015-02-15 13:36:06 +00:00
if just_started_tmux_server; then
start_auto_restore_in_background
fi
2015-02-12 02:37:34 +00:00
fi
2015-02-11 14:43:37 +00:00
}
main