b57284244ed14fb5e9be027e32f8dd3cb664b53d

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1632 from jmatth/tmux_plugin

Adding Tmux Plugin

Diff

  1diff --git a/plugins/tmux/tmux.extra.conf b/plugins/tmux/tmux.extra.conf
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..beffd380c43077053ebf193475b4c1982722103a
  4--- /dev/null
  5+++ b/plugins/tmux/tmux.extra.conf
  6@@ -0,0 +1,2 @@
  7+set -g default-terminal $ZSH_TMUX_TERM
  8+source $HOME/.tmux.conf
  9diff --git a/plugins/tmux/tmux.only.conf b/plugins/tmux/tmux.only.conf
 10new file mode 100644
 11index 0000000000000000000000000000000000000000..0734df3e17fd8b59629507b063b90219305ea038
 12--- /dev/null
 13+++ b/plugins/tmux/tmux.only.conf
 14@@ -0,0 +1 @@
 15+set -g default-terminal $ZSH_TMUX_TERM
 16diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh
 17new file mode 100644
 18index 0000000000000000000000000000000000000000..465f5b053696789317b2854c20764d585f337424
 19--- /dev/null
 20+++ b/plugins/tmux/tmux.plugin.zsh
 21@@ -0,0 +1,85 @@
 22+# Only run if tmux is actually installed
 23+if which tmux &> /dev/null
 24+	then
 25+	# Configuration variables
 26+	#
 27+	# Automatically start tmux
 28+	[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
 29+	# Only autostart once. If set to false, tmux will attempt to
 30+	# autostart every time your zsh configs are reloaded.
 31+	[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
 32+	# Automatically connect to a previous session if it exists
 33+	[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
 34+	# Automatically close the terminal when tmux exits
 35+	[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
 36+	# Set term to screen or screen-256color based on current terminal support
 37+	[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
 38+	# The TERM to use for non-256 color terminals.
 39+	# Tmux states this should be screen, but you may need to change it on
 40+	# systems without the proper terminfo
 41+	[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen"
 42+	# The TERM to use for 256 color terminals.
 43+	# Tmux states this should be screen-256color, but you may need to change it on
 44+	# systems without the proper terminfo
 45+	[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
 46+
 47+
 48+	# Get the absolute path to the current directory
 49+	local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)"
 50+
 51+	# Determine if the terminal supports 256 colors
 52+	if [[ `tput colors` == "256" ]]
 53+	then
 54+		export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
 55+	else
 56+		export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
 57+	fi
 58+
 59+	# Set the correct local config file to use.
 60+	if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
 61+	then
 62+		#use this when they have a ~/.tmux.conf
 63+		export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
 64+	else
 65+		#use this when they don't have a ~/.tmux.conf
 66+		export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
 67+	fi
 68+
 69+	# Wrapper function for tmux.
 70+	function _zsh_tmux_plugin_run()
 71+	{
 72+		# We have other arguments, just run them
 73+		if [[ -n "$@" ]]
 74+		then
 75+			\tmux $@
 76+		# Try to connect to an existing session.
 77+		elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
 78+		then
 79+			\tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`  new-session
 80+			[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
 81+		# Just run tmux, fixing the TERM variable if requested.
 82+		else
 83+			\tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`
 84+			[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
 85+		fi
 86+	}
 87+
 88+	# Use the completions for tmux for our function
 89+	compdef _tmux _zsh_tmux_plugin_run
 90+
 91+	# Alias tmux to our wrapper function.
 92+	alias tmux=_zsh_tmux_plugin_run
 93+
 94+	# Autostart if not already in tmux and enabled.
 95+	if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
 96+	then
 97+		# Actually don't autostart if we already did and multiple autostarts are disabled.
 98+		if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
 99+		then
100+			export ZSH_TMUX_AUTOSTARTED=true
101+			_zsh_tmux_plugin_run
102+		fi
103+	fi
104+else
105+	print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
106+fi