Skip to content

Commit

Permalink
Make tmux plugin refresh tmux global environments automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
delphij committed Aug 4, 2016
1 parent f553724 commit c946c67
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/tmux/tmux.plugin.zsh
Expand Up @@ -22,6 +22,8 @@ if which tmux &> /dev/null
[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
# Automatically close the terminal when tmux exits
[[ -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
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
# Set '-CC' option for iTerm2 tmux integration
Expand Down Expand Up @@ -76,6 +78,12 @@ if which tmux &> /dev/null
fi
}

# Refresh tmux environment variables.
function _zsh_tmux_plugin_precmd()
{
eval $(tmux show-environment -s)
}

# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run

Expand All @@ -92,6 +100,13 @@ if which tmux &> /dev/null
_zsh_tmux_plugin_run
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 precmd _zsh_tmux_plugin_precmd
fi
else
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
fi

0 comments on commit c946c67

Please sign in to comment.