Keep tmux CMUX sync scoped to the workspace

This commit is contained in:
Lawrence Chen 2026-03-21 02:51:20 -07:00
parent af5207db3c
commit 5051123c14
No known key found for this signature in database
2 changed files with 26 additions and 6 deletions

View file

@ -63,7 +63,6 @@ _CMUX_TMUX_SYNC_KEYS=(
CMUXTERM_REPO_ROOT
CMUX_DEBUG_LOG
CMUX_LOAD_GHOSTTY_ZSH_INTEGRATION
CMUX_PANEL_ID
CMUX_PORT
CMUX_PORT_END
CMUX_PORT_RANGE
@ -73,12 +72,20 @@ _CMUX_TMUX_SYNC_KEYS=(
CMUX_SOCKET_ENABLE
CMUX_SOCKET_MODE
CMUX_SOCKET_PATH
CMUX_SURFACE_ID
CMUX_TAB_ID
CMUX_TAG
CMUX_WORKSPACE_ID
)
_cmux_tmux_sync_key_is_managed() {
local candidate="$1"
local key
for key in "${_CMUX_TMUX_SYNC_KEYS[@]}"; do
[[ "$key" == "$candidate" ]] && return 0
done
return 1
}
_cmux_tmux_shell_env_signature() {
local key value first=1
for key in "${_CMUX_TMUX_SYNC_KEYS[@]}"; do
@ -121,6 +128,8 @@ _cmux_tmux_refresh_cmux_environment() {
while IFS= read -r line; do
[[ "$line" == CMUX_* ]] || continue
key="${line%%=*}"
_cmux_tmux_sync_key_is_managed "$key" || continue
filtered+="${line}"$'\n'
done <<< "$output"
@ -130,6 +139,7 @@ _cmux_tmux_refresh_cmux_environment() {
while IFS= read -r line; do
[[ "$line" == CMUX_* ]] || continue
key="${line%%=*}"
_cmux_tmux_sync_key_is_managed "$key" || continue
value="${line#*=}"
if [[ "${!key}" != "$value" ]]; then
printf -v "$key" '%s' "$value"

View file

@ -69,7 +69,6 @@ typeset -ga _CMUX_TMUX_SYNC_KEYS=(
CMUXTERM_REPO_ROOT
CMUX_DEBUG_LOG
CMUX_LOAD_GHOSTTY_ZSH_INTEGRATION
CMUX_PANEL_ID
CMUX_PORT
CMUX_PORT_END
CMUX_PORT_RANGE
@ -79,12 +78,20 @@ typeset -ga _CMUX_TMUX_SYNC_KEYS=(
CMUX_SOCKET_ENABLE
CMUX_SOCKET_MODE
CMUX_SOCKET_PATH
CMUX_SURFACE_ID
CMUX_TAB_ID
CMUX_TAG
CMUX_WORKSPACE_ID
)
_cmux_tmux_sync_key_is_managed() {
local candidate="$1"
local key
for key in "${_CMUX_TMUX_SYNC_KEYS[@]}"; do
[[ "$key" == "$candidate" ]] && return 0
done
return 1
}
_cmux_tmux_shell_env_signature() {
local key value
local -a parts
@ -122,19 +129,22 @@ _cmux_tmux_refresh_cmux_environment() {
local output
output="$(tmux show-environment -g 2>/dev/null)" || return 0
local line filtered="" did_change=0
local line key filtered="" did_change=0
while IFS= read -r line; do
[[ "$line" == CMUX_* ]] || continue
key="${line%%=*}"
_cmux_tmux_sync_key_is_managed "$key" || continue
filtered+="${line}"$'\n'
done <<< "$output"
[[ -n "$filtered" ]] || return 0
[[ "$filtered" == "$_CMUX_TMUX_PULL_SIGNATURE" ]] && return 0
local key value
local value
while IFS= read -r line; do
[[ "$line" == CMUX_* ]] || continue
key="${line%%=*}"
_cmux_tmux_sync_key_is_managed "$key" || continue
value="${line#*=}"
if [[ "${(P)key}" != "$value" ]]; then
export "$key=$value"