tmux.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Configuration variables
  2. # Automatically start tmux
  3. [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
  4. # Automatically connect to a previous session if it exists
  5. [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
  6. # Automatically close the terminal when tmux exits
  7. [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
  8. # Set term to screen or screen-256color based on current terminal support
  9. [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_AUTOCONNECT=true
  10. # Get the absolute path to the current directory
  11. local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)"
  12. # Determine if the terminal supports 256 colors
  13. if [[ `tput colors` == "256" ]]
  14. then
  15. export $ZSH_TMUX_TERM="screen-256"
  16. else
  17. export $ZSH_TMUX_TERM="screen"
  18. fi
  19. # Local variable to store the local config file to use, if any.
  20. local fixed_config=""
  21. # Set the correct local config file to use
  22. if [[ "$ZSH_TMUX_FIXTERM" == "true" ]]
  23. then
  24. if [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
  25. then
  26. fixed_config=$zsh_tmux_plugin_path/tmux.extra.conf
  27. else
  28. fixed_config=$zsh_tmux_plugin_path/tmux.only.conf
  29. fi
  30. fi
  31. # Override tmux with our function
  32. function zsh_tmux_plugin_start()
  33. {
  34. if [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
  35. then
  36. \tmux attach || tmux -f $fixed_config new-session
  37. [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
  38. else
  39. \tmux -f $fixed_config
  40. [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
  41. fi
  42. }
  43. alias tmux=zsh_tmux_plugin_start