691630a89586c86dfafa32974c5c6dbaa1356c07

Author
Josh Matthews <jmatth@nbcs.rutgers.edu>
Committer
Josh Matthews <jmatth@nbcs.rutgers.edu>
Date

Message

Adding option to prevent autostarting tmux more than once in the same session.

Diff

 1diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh
 2index 8bdd92133095c71553a82924ab4d20beef2d0d02..a7bf93dbd087394cf491b90423783c6f510e0a8c 100644
 3--- a/plugins/tmux/tmux.plugin.zsh
 4+++ b/plugins/tmux/tmux.plugin.zsh
 5@@ -1,6 +1,10 @@
 6 # Configuration variables
 7+#
 8 # Automatically start tmux
 9 [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
10+# Only autostart once. If set to false, tmux will attempt to
11+# autostart every time your zsh configs are reloaded.
12+[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
13 # Automatically connect to a previous session if it exists
14 [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
15 # Automatically close the terminal when tmux exits
16@@ -8,6 +12,7 @@
17 # Set term to screen or screen-256color based on current terminal support
18 [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
19 
20+
21 # Get the absolute path to the current directory
22 local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)"
23 
24@@ -54,7 +59,13 @@ function zsh_tmux_plugin_run()
25 # Alias tmux to our wrapper function.
26 alias tmux=zsh_tmux_plugin_start
27 
28+# Autostart if not already in tmux and enabled.
29 if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
30 then
31-	zsh_tmux_plugin_run
32+	# Actually don't autostart if we already did and multiple autostarts are disabled.
33+	if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
34+	then
35+		export ZSH_TMUX_AUTOSTARTED=true
36+		zsh_tmux_plugin_run
37+	fi
38 fi