f584de5930467fd53e8b7d2e51f5227bc405e4b2

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

tmux: refactor and simplify tmux function logic

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh
  2index 1b97cae7367b5d5baa4f7878c639c95eb92e1cd9..2d161c37719c322be2d0199250afd01fab00fef6 100644
  3--- a/plugins/tmux/tmux.plugin.zsh
  4+++ b/plugins/tmux/tmux.plugin.zsh
  5@@ -1,6 +1,9 @@
  6-#
  7-# Aliases
  8-#
  9+if ! (( $+commands[tmux] )); then
 10+  print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2
 11+  return 1
 12+fi
 13+
 14+# ALIASES
 15 
 16 alias ta='tmux attach -t'
 17 alias tad='tmux attach -d -t'
 18@@ -9,85 +12,76 @@ alias tl='tmux list-sessions'
 19 alias tksv='tmux kill-server'
 20 alias tkss='tmux kill-session -t'
 21 
 22-# Only run if tmux is actually installed
 23-if ! which tmux &> /dev/null; then
 24-  print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2
 25-  return 1
 26-fi
 27-
 28-# Configuration variables
 29-#
 30+# CONFIGURATION VARIABLES
 31 # Automatically start tmux
 32-[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
 33+: ${ZSH_TMUX_AUTOSTART:=false}
 34 # Only autostart once. If set to false, tmux will attempt to
 35 # autostart every time your zsh configs are reloaded.
 36-[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
 37+: ${ZSH_TMUX_AUTOSTART_ONCE:=true}
 38 # Automatically connect to a previous session if it exists
 39-[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
 40+: ${ZSH_TMUX_AUTOCONNECT:=true}
 41 # Automatically close the terminal when tmux exits
 42-[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
 43+: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART}
 44 # Set term to screen or screen-256color based on current terminal support
 45-[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
 46+: ${ZSH_TMUX_FIXTERM:=true}
 47 # Set '-CC' option for iTerm2 tmux integration
 48-[[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false
 49+: ${ZSH_TMUX_ITERM2:=false}
 50 # The TERM to use for non-256 color terminals.
 51 # Tmux states this should be screen, but you may need to change it on
 52 # systems without the proper terminfo
 53-[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen"
 54+: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen}
 55 # The TERM to use for 256 color terminals.
 56 # Tmux states this should be screen-256color, but you may need to change it on
 57 # systems without the proper terminfo
 58-[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
 59-
 60+: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color}
 61 
 62 # Determine if the terminal supports 256 colors
 63-if [[ `tput colors` == "256" ]]; then
 64+if [[ $(tput colors) == 256 ]]; then
 65   export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
 66 else
 67   export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
 68 fi
 69 
 70 # Set the correct local config file to use.
 71-if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]; then
 72-  #use this when they have a ~/.tmux.conf
 73+if [[ "$ZSH_TMUX_ITERM2" == "false" && -e "$HOME/.tmux.conf" ]]; then
 74   export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.extra.conf"
 75 else
 76-  #use this when they don't have a ~/.tmux.conf
 77   export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.only.conf"
 78 fi
 79 
 80 # Wrapper function for tmux.
 81 function _zsh_tmux_plugin_run() {
 82-  local tmux_cmd
 83-  tmux_cmd=(command tmux)
 84-  [[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+="-CC"
 85-  [[ "$ZSH_TMUX_FIXTERM" == "true" ]] && tmux_cmd+=(-f $_ZSH_TMUX_FIXED_CONFIG)
 86   if [[ -n "$@" ]]; then
 87-    # We have other arguments, just run them
 88-    \tmux $@
 89-  elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]; then
 90-    # Try to connect to an existing session.
 91-    $tmux_cmd attach || $tmux_cmd new-session
 92-    if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then
 93-      exit
 94-    fi
 95-  else
 96-    # Just run tmux, fixing the TERM variable if requested.
 97-    $tmux_cmd
 98-    if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then
 99-      exit
100-    fi
101+    command tmux "$@"
102+    return $?
103+  fi
104+