summaryrefslogtreecommitdiff
path: root/plugins/tmux
diff options
context:
space:
mode:
authorXin Li <delphij@users.noreply.github.com>2025-03-20 12:25:40 -0700
committerGitHub <noreply@github.com>2025-03-20 20:25:40 +0100
commitec07c79d7ef9f30d4f7aef7eb54b605cd78bfb3d (patch)
treecea25eaccd186973a7b53a9940b6e8d557dfe6b1 /plugins/tmux
parent068299685ceac5af570232ca5daa0ecd4d1f7d62 (diff)
downloadzsh-ec07c79d7ef9f30d4f7aef7eb54b605cd78bfb3d.tar.gz
zsh-ec07c79d7ef9f30d4f7aef7eb54b605cd78bfb3d.tar.bz2
zsh-ec07c79d7ef9f30d4f7aef7eb54b605cd78bfb3d.zip
feat(tmux): refresh global environments automatically (#5282)
Diffstat (limited to 'plugins/tmux')
-rw-r--r--plugins/tmux/tmux.plugin.zsh17
1 files changed, 17 insertions, 0 deletions
diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh
index 51cc7d6a5..f6de9166f 100644
--- a/plugins/tmux/tmux.plugin.zsh
+++ b/plugins/tmux/tmux.plugin.zsh
@@ -15,6 +15,8 @@ fi
: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART}
# Automatically name the new session based on the basename of PWD
: ${ZSH_TMUX_AUTONAME_SESSION:=false}
+# Automatically pick up tmux environments
+: ${ZSH_TMUX_AUTOREFRESH:=true}
# Set term to screen or screen-256color based on current terminal support
: ${ZSH_TMUX_DETACHED:=false}
# Set detached mode
@@ -158,6 +160,15 @@ function _zsh_tmux_plugin_run() {
fi
}
+# Refresh tmux environment variables.
+function _zsh_tmux_plugin_preexec()
+{
+ local -a tmux_cmd
+ tmux_cmd=(command tmux)
+
+ eval $($tmux_cmd show-environment -s)
+}
+
# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run
# Alias tmux to our wrapper function.
@@ -184,3 +195,9 @@ if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z
_zsh_tmux_plugin_run
fi
fi
+
+# Automatically refresh tmux environments if tmux is running.
+if [[ -n "$TMUX" && "$ZSH_TMUX_AUTOREFRESH" == "true" ]] && tmux ls >/dev/null 2>/dev/null; then
+ autoload -U add-zsh-hook
+ add-zsh-hook preexec _zsh_tmux_plugin_preexec
+fi