From b979400cff17248147d95f6271edb6f2d6e36c84 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 14:05:22 -0500 Subject: [PATCH 01/17] Starting tmux plugin with basic config variables. --- plugins/tmux/tmux.plugin.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 plugins/tmux/tmux.plugin.zsh diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh new file mode 100644 index 00000000..cc676cb9 --- /dev/null +++ b/plugins/tmux/tmux.plugin.zsh @@ -0,0 +1,12 @@ +# Configuration variables +# Automatically start tmux +[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART = false +# Automatically connect to a previous session if it exists +[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT = true +# Automatically close the terminal when tmux exits +[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT = true +# Set term to screen or screen-256color based on current terminal support +[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_AUTOCONNECT = true + +# Get the absolute path to the current directory +local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" From 26ee66f179be08fab59d41a0522ad51610125c6c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 17:50:15 -0500 Subject: [PATCH 02/17] Adding main function and alias to tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index cc676cb9..a2f36c0b 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -1,12 +1,41 @@ # Configuration variables # Automatically start tmux -[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART = false +[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false # Automatically connect to a previous session if it exists -[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT = true +[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true # Automatically close the terminal when tmux exits -[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT = true +[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART # Set term to screen or screen-256color based on current terminal support -[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_AUTOCONNECT = true +[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_AUTOCONNECT=true # Get the absolute path to the current directory local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" + +# Local variable to store the local config file to use, if any. +local fixed_config="" + +# Set the correct local config file to use +if [[ "$ZSH_TMUX_FIXTERM" == "true" ]] +then + if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] + then + fixed_config=$zsh_tmux_plugin_path/tmux.extra.conf + else + fixed_config=$zsh_tmux_plugin_path/tmux.only.conf + fi +fi + +# Override tmux with our function +function zsh_tmux_plugin_start() +{ + if [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] + then + \tmux attach || tmux -f $fixed_config new-session + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + else + \tmux -f $fixed_config + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + fi +} + +alias tmux=zsh_tmux_plugin_start From 3aef6793c2bf0c0afec1fdb97a3a56e7f8d065c6 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 18:05:58 -0500 Subject: [PATCH 03/17] Now checking for 256 color terminal in tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index a2f36c0b..f67c2b8b 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -11,6 +11,14 @@ # Get the absolute path to the current directory local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" +# Determine if the terminal supports 256 colors +if [[ `tput colors` == "256" ]] +then + export $ZSH_TMUX_TERM="screen-256" +else + export $ZSH_TMUX_TERM="screen" +fi + # Local variable to store the local config file to use, if any. local fixed_config="" From 778ae57772a02d11c393708c4c0644fbd1ffac35 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 18:07:25 -0500 Subject: [PATCH 04/17] Tmux plugin now just runs tmux if any extra args are given. --- plugins/tmux/tmux.plugin.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index f67c2b8b..d8fdd925 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -36,7 +36,12 @@ fi # Override tmux with our function function zsh_tmux_plugin_start() { - if [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] + # We have other arguments, just run them + if [[ ! -n "$@" ]] + then + \tmux $@ + # Try to connect to an existing session. + elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] then \tmux attach || tmux -f $fixed_config new-session [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit From 0cf871d51299a4f837e6dce4d4ae827b0c09f5bd Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 18:08:37 -0500 Subject: [PATCH 05/17] Adding comments to tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index d8fdd925..48ffc1c2 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -27,8 +27,10 @@ if [[ "$ZSH_TMUX_FIXTERM" == "true" ]] then if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] then + #use this when they have a ~/.tmux.conf fixed_config=$zsh_tmux_plugin_path/tmux.extra.conf else + #use this when they don't have a ~/.tmux.conf fixed_config=$zsh_tmux_plugin_path/tmux.only.conf fi fi @@ -45,6 +47,7 @@ function zsh_tmux_plugin_start() then \tmux attach || tmux -f $fixed_config new-session [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + # Just try to fix the TERM variable. else \tmux -f $fixed_config [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit From 45a4db33f81c5dbdcafa25cfe5a75490d55ec185 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 18:09:01 -0500 Subject: [PATCH 06/17] Enabling autostart of tmux in tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 48ffc1c2..8dd20839 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -55,3 +55,8 @@ function zsh_tmux_plugin_start() } alias tmux=zsh_tmux_plugin_start + +if [[ "$ZSH_TMUX_AUTOSTART" == "true" ]] +then + zsh_tmux_plugin_start +fi From bf40d4e354ce33c0d9f42cc64372461bff14cde8 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 18:09:17 -0500 Subject: [PATCH 07/17] Adding helper tmux config files to tmux plugin. --- plugins/tmux/tmux.extra.conf | 2 ++ plugins/tmux/tmux.only.conf | 1 + 2 files changed, 3 insertions(+) create mode 100644 plugins/tmux/tmux.extra.conf create mode 100644 plugins/tmux/tmux.only.conf diff --git a/plugins/tmux/tmux.extra.conf b/plugins/tmux/tmux.extra.conf new file mode 100644 index 00000000..beffd380 --- /dev/null +++ b/plugins/tmux/tmux.extra.conf @@ -0,0 +1,2 @@ +set -g default-terminal $ZSH_TMUX_TERM +source $HOME/.tmux.conf diff --git a/plugins/tmux/tmux.only.conf b/plugins/tmux/tmux.only.conf new file mode 100644 index 00000000..0734df3e --- /dev/null +++ b/plugins/tmux/tmux.only.conf @@ -0,0 +1 @@ +set -g default-terminal $ZSH_TMUX_TERM From 7b15627851983e63a5756f0b3633938c44ed7a7d Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 21:47:11 -0500 Subject: [PATCH 08/17] Fixing typos, logic, and gremlins in tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 8dd20839..46c142b7 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -6,7 +6,7 @@ # Automatically close the terminal when tmux exits [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART # Set term to screen or screen-256color based on current terminal support -[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_AUTOCONNECT=true +[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true # Get the absolute path to the current directory local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" @@ -14,49 +14,50 @@ local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" # Determine if the terminal supports 256 colors if [[ `tput colors` == "256" ]] then - export $ZSH_TMUX_TERM="screen-256" + export ZSH_TMUX_TERM="screen-256color" else - export $ZSH_TMUX_TERM="screen" + export ZSH_TMUX_TERM="screen" fi # Local variable to store the local config file to use, if any. local fixed_config="" -# Set the correct local config file to use +# Set the correct local config file to use. if [[ "$ZSH_TMUX_FIXTERM" == "true" ]] then if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] then #use this when they have a ~/.tmux.conf - fixed_config=$zsh_tmux_plugin_path/tmux.extra.conf + fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" else #use this when they don't have a ~/.tmux.conf - fixed_config=$zsh_tmux_plugin_path/tmux.only.conf + fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" fi fi -# Override tmux with our function -function zsh_tmux_plugin_start() +# Wrapper function for tmux. +function zsh_tmux_plugin_run() { # We have other arguments, just run them - if [[ ! -n "$@" ]] + if [[ -n "$@" ]] then \tmux $@ # Try to connect to an existing session. elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] then - \tmux attach || tmux -f $fixed_config new-session + \tmux attach || \tmux `[[ -n "$fixed_config" ]] && echo '-f ' $fixed_config` new-session [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit - # Just try to fix the TERM variable. + # Just run tmux, fixing the TERM variable if requested. else - \tmux -f $fixed_config + \tmux `[[ -n "$fixed_config" ]] && echo '-f ' $fixed_config` [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit fi } +# Alias tmux to our wrapper function. alias tmux=zsh_tmux_plugin_start if [[ "$ZSH_TMUX_AUTOSTART" == "true" ]] then - zsh_tmux_plugin_start + zsh_tmux_plugin_run fi From 43c50f03e3c547ec51feef7ae3c99f734a66e6a6 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 21:52:26 -0500 Subject: [PATCH 09/17] Checking environment instead of local variable for fixing term in tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 46c142b7..9a52e637 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -23,16 +23,13 @@ fi local fixed_config="" # Set the correct local config file to use. -if [[ "$ZSH_TMUX_FIXTERM" == "true" ]] +if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] then - if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] - then - #use this when they have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" - else - #use this when they don't have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" - fi + #use this when they have a ~/.tmux.conf + fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" +else + #use this when they don't have a ~/.tmux.conf + fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" fi # Wrapper function for tmux. @@ -45,11 +42,11 @@ function zsh_tmux_plugin_run() # Try to connect to an existing session. elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] then - \tmux attach || \tmux `[[ -n "$fixed_config" ]] && echo '-f ' $fixed_config` new-session + \tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` new-session [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit # Just run tmux, fixing the TERM variable if requested. else - \tmux `[[ -n "$fixed_config" ]] && echo '-f ' $fixed_config` + \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit fi } From f096644c751cb7fe566e82de531435a405d76be8 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 22:03:22 -0500 Subject: [PATCH 10/17] Checking if already in tmux before autostarting in tmux in tmux plugin. --- plugins/tmux/tmux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 9a52e637..8bdd9213 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -54,7 +54,7 @@ function zsh_tmux_plugin_run() # Alias tmux to our wrapper function. alias tmux=zsh_tmux_plugin_start -if [[ "$ZSH_TMUX_AUTOSTART" == "true" ]] +if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] then zsh_tmux_plugin_run fi From 691630a89586c86dfafa32974c5c6dbaa1356c07 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 22:18:36 -0500 Subject: [PATCH 11/17] Adding option to prevent autostarting tmux more than once in the same session. --- plugins/tmux/tmux.plugin.zsh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 8bdd9213..a7bf93db 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -1,6 +1,10 @@ # Configuration variables +# # Automatically start tmux [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false +# Only autostart once. If set to false, tmux will attempt to +# autostart every time your zsh configs are reloaded. +[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true # Automatically connect to a previous session if it exists [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true # Automatically close the terminal when tmux exits @@ -8,6 +12,7 @@ # Set term to screen or screen-256color based on current terminal support [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true + # Get the absolute path to the current directory local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" @@ -54,7 +59,13 @@ function zsh_tmux_plugin_run() # Alias tmux to our wrapper function. alias tmux=zsh_tmux_plugin_start +# Autostart if not already in tmux and enabled. if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] then - zsh_tmux_plugin_run + # Actually don't autostart if we already did and multiple autostarts are disabled. + if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] + then + export ZSH_TMUX_AUTOSTARTED=true + zsh_tmux_plugin_run + fi fi From 56c46c4ed8339c66c671927c197eb4511b5a664c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 22:55:18 -0500 Subject: [PATCH 12/17] Fixing typo in alias. --- plugins/tmux/tmux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index a7bf93db..982f8735 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -57,7 +57,7 @@ function zsh_tmux_plugin_run() } # Alias tmux to our wrapper function. -alias tmux=zsh_tmux_plugin_start +alias tmux=zsh_tmux_plugin_run # Autostart if not already in tmux and enabled. if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] From 86c9b32031dc28b4c6a641a4475e0e55c7ff32e5 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 22:57:37 -0500 Subject: [PATCH 13/17] Adding compdef to maintain tmux completions. --- plugins/tmux/tmux.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 982f8735..5c407690 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -56,6 +56,9 @@ function zsh_tmux_plugin_run() fi } +# Use the completions for tmux for our function +compdef _tmux zsh_tmux_plugin_run + # Alias tmux to our wrapper function. alias tmux=zsh_tmux_plugin_run From 4e8681c6e19f77a9b54ceee5934e3356e4ffb207 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Feb 2013 23:35:45 -0500 Subject: [PATCH 14/17] Adding options to choose tmux TERM for 256 and non-256 color terminals. This may be needed on systems that don't have the proper terminfo for screen and/or screen-256color. Otherwise the defaults of screen and screen-256color should be fine. --- plugins/tmux/tmux.plugin.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 5c407690..be92fe09 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -11,6 +11,14 @@ [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART # Set term to screen or screen-256color based on current terminal support [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true +# The TERM to use for non-256 color terminals. +# Tmux states this should be screen, but you may need to change it on +# systems without the proper terminfo +[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" +# The TERM to use for 256 color terminals. +# Tmux states this should be screen-256color, but you may need to change it on +# systems without the proper terminfo +[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" # Get the absolute path to the current directory @@ -19,9 +27,9 @@ local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" # Determine if the terminal supports 256 colors if [[ `tput colors` == "256" ]] then - export ZSH_TMUX_TERM="screen-256color" + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR else - export ZSH_TMUX_TERM="screen" + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR fi # Local variable to store the local config file to use, if any. From f0a920df5a4a5e5260ef45daf27d42a15cd75217 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 27 Feb 2013 10:21:19 -0500 Subject: [PATCH 15/17] Checking to make sure tmux is actually installed before running plugin. If it is not found an error message is printed. --- plugins/tmux/tmux.plugin.zsh | 152 ++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 73 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index be92fe09..6f0d5902 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -1,82 +1,88 @@ -# Configuration variables -# -# Automatically start tmux -[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false -# Only autostart once. If set to false, tmux will attempt to -# autostart every time your zsh configs are reloaded. -[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true -# Automatically connect to a previous session if it exists -[[ -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 -# Set term to screen or screen-256color based on current terminal support -[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true -# The TERM to use for non-256 color terminals. -# Tmux states this should be screen, but you may need to change it on -# systems without the proper terminfo -[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" -# The TERM to use for 256 color terminals. -# Tmux states this should be screen-256color, but you may need to change it on -# systems without the proper terminfo -[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" - - -# Get the absolute path to the current directory -local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" - -# Determine if the terminal supports 256 colors -if [[ `tput colors` == "256" ]] -then - export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR -else - export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR -fi - -# Local variable to store the local config file to use, if any. -local fixed_config="" - -# Set the correct local config file to use. -if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] -then - #use this when they have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" -else - #use this when they don't have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" -fi - -# Wrapper function for tmux. -function zsh_tmux_plugin_run() -{ - # We have other arguments, just run them - if [[ -n "$@" ]] +# Only run if tmux is actually installed +if which tmux &> /dev/null then - \tmux $@ - # Try to connect to an existing session. - elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] + # Configuration variables + # + # Automatically start tmux + [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false + # Only autostart once. If set to false, tmux will attempt to + # autostart every time your zsh configs are reloaded. + [[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true + # Automatically connect to a previous session if it exists + [[ -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 + # Set term to screen or screen-256color based on current terminal support + [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true + # The TERM to use for non-256 color terminals. + # Tmux states this should be screen, but you may need to change it on + # systems without the proper terminfo + [[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" + # The TERM to use for 256 color terminals. + # Tmux states this should be screen-256color, but you may need to change it on + # systems without the proper terminfo + [[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" + + + # Get the absolute path to the current directory + local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" + + # Determine if the terminal supports 256 colors + if [[ `tput colors` == "256" ]] then - \tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` new-session - [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit - # Just run tmux, fixing the TERM variable if requested. + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR else - \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` - [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR fi -} -# Use the completions for tmux for our function -compdef _tmux zsh_tmux_plugin_run + # Local variable to store the local config file to use, if any. + local fixed_config="" -# Alias tmux to our wrapper function. -alias tmux=zsh_tmux_plugin_run - -# Autostart if not already in tmux and enabled. -if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] -then - # Actually don't autostart if we already did and multiple autostarts are disabled. - if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] + # Set the correct local config file to use. + if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] then - export ZSH_TMUX_AUTOSTARTED=true - zsh_tmux_plugin_run + #use this when they have a ~/.tmux.conf + fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" + else + #use this when they don't have a ~/.tmux.conf + fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" fi + + # Wrapper function for tmux. + function zsh_tmux_plugin_run() + { + # We have other arguments, just run them + if [[ -n "$@" ]] + then + \tmux $@ + # Try to connect to an existing session. + elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] + then + \tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` new-session + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + # Just run tmux, fixing the TERM variable if requested. + else + \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + fi + } + + # Use the completions for tmux for our function + compdef _tmux zsh_tmux_plugin_run + + # Alias tmux to our wrapper function. + alias tmux=zsh_tmux_plugin_run + + # Autostart if not already in tmux and enabled. + if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] + then + # Actually don't autostart if we already did and multiple autostarts are disabled. + if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] + then + export ZSH_TMUX_AUTOSTARTED=true + zsh_tmux_plugin_run + fi + fi +else + print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." fi From a91872df35d15f0544339ae9c61f87e761c19827 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Mar 2013 19:41:34 +0000 Subject: [PATCH 16/17] Prefixing tmux wrapper function with '_'. --- plugins/tmux/tmux.plugin.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 6f0d5902..ea6b4d26 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -49,7 +49,7 @@ if which tmux &> /dev/null fi # Wrapper function for tmux. - function zsh_tmux_plugin_run() + function _zsh_tmux_plugin_run() { # We have other arguments, just run them if [[ -n "$@" ]] @@ -68,10 +68,10 @@ if which tmux &> /dev/null } # Use the completions for tmux for our function - compdef _tmux zsh_tmux_plugin_run + compdef _tmux _zsh_tmux_plugin_run # Alias tmux to our wrapper function. - alias tmux=zsh_tmux_plugin_run + alias tmux=_zsh_tmux_plugin_run # Autostart if not already in tmux and enabled. if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] @@ -80,7 +80,7 @@ if which tmux &> /dev/null if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] then export ZSH_TMUX_AUTOSTARTED=true - zsh_tmux_plugin_run + _zsh_tmux_plugin_run fi fi else From 19ae0b576c4fd0c0c4af1a5c491df867fdce39a4 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 26 Mar 2013 19:42:05 +0000 Subject: [PATCH 17/17] Exporting path to fixed config as a global variable. This is done to fix compatibility with antigen. To keep with convention, the variable has been renamed to be in all caps. --- plugins/tmux/tmux.plugin.zsh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index ea6b4d26..465f5b05 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -35,17 +35,14 @@ if which tmux &> /dev/null export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR fi - # Local variable to store the local config file to use, if any. - local fixed_config="" - # Set the correct local config file to use. if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] then #use this when they have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.extra.conf" + export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf" else #use this when they don't have a ~/.tmux.conf - fixed_config="$zsh_tmux_plugin_path/tmux.only.conf" + export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf" fi # Wrapper function for tmux. @@ -58,11 +55,11 @@ if which tmux &> /dev/null # Try to connect to an existing session. elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] then - \tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` new-session + \tmux attach || \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit # Just run tmux, fixing the TERM variable if requested. else - \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$fixed_config` + \tmux `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit fi }