mirror of
https://github.com/tmux-plugins/tmux-continuum.git
synced 2025-09-06 17:07:03 +00:00
Don't start auto-saving if another tmux server is running
This commit is contained in:
@ -14,3 +14,33 @@ set_tmux_option() {
|
||||
local value="$2"
|
||||
tmux set-option -gq "$option" "$value"
|
||||
}
|
||||
|
||||
# multiple tmux server detection helpers
|
||||
|
||||
current_tmux_server_pid() {
|
||||
echo "$TMUX" |
|
||||
cut -f2 -d","
|
||||
}
|
||||
|
||||
all_tmux_processes() {
|
||||
ps -Ao "command pid" |
|
||||
\grep "^tmux"
|
||||
}
|
||||
|
||||
number_tmux_processes_except_current_server() {
|
||||
all_tmux_processes |
|
||||
\grep -v " $(current_tmux_server_pid)$" |
|
||||
wc -l |
|
||||
sed "s/ //g"
|
||||
}
|
||||
|
||||
number_current_server_client_processes() {
|
||||
tmux list-clients |
|
||||
wc -l |
|
||||
sed "s/ //g"
|
||||
}
|
||||
|
||||
another_tmux_server_running_on_startup() {
|
||||
# there are 2 tmux processes (current tmux server + 1) on tmux startup
|
||||
[ "$(number_tmux_processes_except_current_server)" -gt 1 ]
|
||||
}
|
||||
|
@ -10,33 +10,6 @@ auto_restore_enabled() {
|
||||
[ "$auto_restore_value" == "on" ] && [ ! -f "$auto_restore_halt_file" ]
|
||||
}
|
||||
|
||||
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 ]
|
||||
}
|
||||
|
||||
fetch_and_run_tmux_resurrect_restore_script() {
|
||||
# give tmux some time to start and source all the plugins
|
||||
sleep 1
|
||||
@ -47,7 +20,9 @@ fetch_and_run_tmux_resurrect_restore_script() {
|
||||
}
|
||||
|
||||
main() {
|
||||
if auto_restore_enabled && ! another_tmux_server_running; then
|
||||
# Advanced edge case handling: auto restore only if this is the only tmux
|
||||
# server. If another tmux server exists, it is assumed auto-restore is not wanted.
|
||||
if auto_restore_enabled && ! another_tmux_server_running_on_startup; then
|
||||
fetch_and_run_tmux_resurrect_restore_script
|
||||
fi
|
||||
}
|
||||
|
Reference in New Issue
Block a user