2015-02-15 13:36:06 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
source "$CURRENT_DIR/helpers.sh"
|
|
|
|
source "$CURRENT_DIR/variables.sh"
|
|
|
|
|
2015-02-19 12:53:06 +00:00
|
|
|
auto_restore_enabled() {
|
2015-02-15 13:36:06 +00:00
|
|
|
local auto_restore_value="$(get_tmux_option "$auto_restore_option" "$auto_restore_default")"
|
|
|
|
[ "$auto_restore_value" == "on" ] && [ ! -f "$auto_restore_halt_file" ]
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:24:00 +00:00
|
|
|
current_tmux_server_pid() {
|
|
|
|
echo "$TMUX" |
|
|
|
|
cut -f2 -d","
|
|
|
|
}
|
|
|
|
|
|
|
|
all_tmux_processes() {
|
|
|
|
ps -Ao "command pid" |
|
|
|
|
\grep "^tmux"
|
|
|
|
}
|
|
|
|
|
|
|
|
tmux_processes_except_current_server() {
|
|
|
|
all_tmux_processes |
|
|
|
|
\grep -v " $(current_tmux_server_pid)$"
|
|
|
|
}
|
|
|
|
|
|
|
|
number_tmux_processes_except_current_server() {
|
|
|
|
all_tmux_processes |
|
|
|
|
\grep -v " $(current_tmux_server_pid)$" |
|
|
|
|
wc -l |
|
|
|
|
sed "s/ //g"
|
|
|
|
}
|
|
|
|
|
|
|
|
another_tmux_server_running() {
|
|
|
|
# there are 2 tmux processes (current tmux server + 1) on tmux startup
|
|
|
|
[ "$(number_tmux_processes_except_current_server)" -gt 1 ]
|
|
|
|
}
|
|
|
|
|
2015-02-15 13:36:06 +00:00
|
|
|
fetch_and_run_tmux_resurrect_restore_script() {
|
|
|
|
# give tmux some time to start and source all the plugins
|
|
|
|
sleep 1
|
|
|
|
local resurrect_restore_script_path="$(get_tmux_option "$resurrect_restore_path_option" "")"
|
|
|
|
if [ -n "$resurrect_restore_script_path" ]; then
|
|
|
|
"$resurrect_restore_script_path"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2015-02-19 15:24:00 +00:00
|
|
|
if auto_restore_enabled && ! another_tmux_server_running; then
|
2015-02-15 13:36:06 +00:00
|
|
|
fetch_and_run_tmux_resurrect_restore_script
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
main
|