tmux.plugin.zsh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #use this when they have a ~/.tmux.conf
  27. fixed_config=$zsh_tmux_plugin_path/tmux.extra.conf
  28. else
  29. #use this when they don't have a ~/.tmux.conf
  30. fixed_config=$zsh_tmux_plugin_path/tmux.only.conf
  31. fi
  32. fi
  33. # Override tmux with our function
  34. function zsh_tmux_plugin_start()
  35. {
  36. # We have other arguments, just run them
  37. if [[ ! -n "$@" ]]
  38. then
  39. \tmux $@
  40. # Try to connect to an existing session.
  41. elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
  42. then
  43. \tmux attach || tmux -f $fixed_config new-session
  44. [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
  45. # Just try to fix the TERM variable.
  46. else
  47. \tmux -f $fixed_config
  48. [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
  49. fi
  50. }
  51. alias tmux=zsh_tmux_plugin_start
  52. if [[ "$ZSH_TMUX_AUTOSTART" == "true" ]]
  53. then
  54. zsh_tmux_plugin_start
  55. fi