tmux-continuum/scripts/helpers.sh
v9v 1531b3770a
Fix for multiple users on the same machine
The issue and fix are described in https://github.com/tmux-plugins/tmux-continuum/issues/16 .

Without this change, tmux-continuum works only for one tmux server on the machine. In a multi-user environment (e.g. a shared server), when multiple users are running their own tmux servers, this means that tmux-continuum works only for one of the users.

This change enables tmux-continuum for one tmux server per user instead of one tmux server per machine.
2020-02-29 01:37:58 +01:00

50 lines
1.0 KiB
Bash

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
}
set_tmux_option() {
local option="$1"
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() {
# ignores `tmux source-file .tmux.conf` command used to reload tmux.conf
local user_id=$(id -u)
ps -u $user_id -o "command pid" |
\grep "^tmux" |
\grep -v "^tmux source"
}
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 ]
}