Make tmux plugin refresh tmux global environments automatically.

This commit is contained in:
Xin Li 2016-08-03 23:07:38 -07:00 committed by Xin Li
parent b908feebcf
commit 748d1496dc

View File

@ -23,6 +23,8 @@ if which tmux &> /dev/null
[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
# Automatically close the terminal when tmux exits # Automatically close the terminal when tmux exits
[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
# Automatically pick up tmux environments
[[ -n "$ZSH_TMUX_AUTOREFRESH" ]] || ZSH_TMUX_AUTOREFRESH=true
# Set term to screen or screen-256color based on current terminal support # Set term to screen or screen-256color based on current terminal support
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
# Set '-CC' option for iTerm2 tmux integration # Set '-CC' option for iTerm2 tmux integration
@ -77,6 +79,12 @@ if which tmux &> /dev/null
fi fi
} }
# Refresh tmux environment variables.
function _zsh_tmux_plugin_preexec()
{
eval $(tmux show-environment -s)
}
# Use the completions for tmux for our function # Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run compdef _tmux _zsh_tmux_plugin_run
@ -93,6 +101,13 @@ if which tmux &> /dev/null
_zsh_tmux_plugin_run _zsh_tmux_plugin_run
fi fi
fi fi
# Automatically refresh tmux environments if tmux is running.
if [[ -n "$TMUX" && "$ZSH_TMUX_AUTOREFRESH" == "true" ]]
then
autoload -U add-zsh-hook
add-zsh-hook preexec _zsh_tmux_plugin_preexec
fi
else else
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
fi fi