diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-08-08 22:57:01 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-08-08 22:57:01 -0300 |
commit | 04f8ce0edf936e53bc197ac58bb64afcfaaf2219 (patch) | |
tree | 50d51ad2c4f687fdb295fb6fb561745bc54dc65b | |
parent | 9039fd411934413a750ff77eab4d8c632b3e5741 (diff) | |
download | termplex-04f8ce0edf936e53bc197ac58bb64afcfaaf2219.tar.gz termplex-04f8ce0edf936e53bc197ac58bb64afcfaaf2219.tar.bz2 |
Fix: wtmux: session isolation through distinct sockets
-rwxr-xr-x | wtmux | 39 |
1 files changed, 29 insertions, 10 deletions
@@ -15,19 +15,38 @@ opts="" name="$1" state="$2" +socket="-L${name}" # Session selection. if [ ! -z "${name}" ]; then - if ! tmux list-sessions 2> /dev/null | grep -q "^${name}:"; then + if [ "${name}" = "root" ]; then + sudo tmux attach + exit + fi + + if ! tmux ${socket} list-sessions 2> /dev/null | grep -q "^${name}:"; then session="new-session -d -s ${name}" # Use a unique, per-session name - #session"${session} -t ${name}" + #session="${session} -t ${name}" + + # Ensure there's a separate server running for each session. + # + # This achieves session isolation by using a unique socket per session. + # + # This solves tmux creating too many environment variables and triggering + # the following error when using programs such as "less" and "ranger": + # + # Error: too many environment variables: >= MAX_ENVS (256) + # + # For a list of tmux environment variables available within a session, + # type "env | grep TMUX". + # + # Reference: + # https://github.com/tmux/tmux/wiki/Advanced-Use + session="${socket} ${session}" - if [ "${name}" = "root" ]; then - sudo tmux attach - exit - elif [ -f "$HOME/.tmux/${name}" ]; then + if [ -f "$HOME/.tmux/${name}" ]; then opts="$HOME/.tmux/${name}" elif [ -f "$HOME/.tmux/base" ]; then opts="$HOME/.tmux/base" @@ -36,15 +55,15 @@ if [ ! -z "${name}" ]; then fi # Start session. - if [ ! -z "$opts" ]; then - tmux $session \; source-file $opts + if [ ! -z "${opts}" ]; then + tmux ${session} \; source-file ${opts} else - tmux $session + tmux ${session} fi fi if [ "$state" != "detached" ]; then - tmux attach -t ${name} + tmux ${socket} attach -t ${name} fi else tmux |