From c891b7e6ada5427f4c8cca05c8ed1ae33cb49943 Mon Sep 17 00:00:00 2001 From: Dusk Date: Tue, 27 Feb 2024 15:09:02 -0400 Subject: feat(tmux): add option for detached mode (#12242) --- plugins/tmux/README.md | 15 ++++++++------- plugins/tmux/tmux.plugin.zsh | 6 ++++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index b4516ef26..a253457f2 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -19,13 +19,13 @@ The plugin also supports the following: | ---------- | -------------------------- | -------------------------------------------------------- | | `ta` | tmux attach -t | Attach new tmux session to already running named session | | `tad` | tmux attach -d -t | Detach named tmux session | -| `ts` | tmux new-session -s | Create a new named tmux session | -| `tl` | tmux list-sessions | Displays a list of running tmux sessions | -| `tksv` | tmux kill-server | Terminate all running tmux sessions | +| `tds` | `_tmux_directory_session` | Creates or attaches to a session for the current path | | `tkss` | tmux kill-session -t | Terminate named running tmux session | +| `tksv` | tmux kill-server | Terminate all running tmux sessions | +| `tl` | tmux list-sessions | Displays a list of running tmux sessions | | `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session | | `tmuxconf` | `$EDITOR $ZSH_TMUX_CONFIG` | Open .tmux.conf file with an editor | -| `tds` | `_tmux_directory_session` | Creates or attaches to a session for the current path | +| `ts` | tmux new-session -s | Create a new named tmux session | ## Configuration Variables @@ -35,10 +35,11 @@ The plugin also supports the following: | `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | | `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | | `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | +| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | | `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | -| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | | `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | | `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | -| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | | `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | -| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 72cdd4818..0ecb0a5b5 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -14,6 +14,8 @@ fi # Automatically close the terminal when tmux exits : ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART} # Set term to screen or screen-256color based on current terminal support +: ${ZSH_TMUX_DETACHED:=false} +# Set detached mode : ${ZSH_TMUX_FIXTERM:=true} # Set '-CC' option for iTerm2 tmux integration : ${ZSH_TMUX_ITERM2:=false} @@ -79,9 +81,9 @@ function _zsh_tmux_plugin_run() { # Try to connect to an existing session. if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach -t $ZSH_TMUX_DEFAULT_SESSION_NAME + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach ${ZSH_TMUX_DETACHED:+"-d"} -t $ZSH_TMUX_DEFAULT_SESSION_NAME else - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach ${ZSH_TMUX_DETACHED:+"-d"} fi # If failed, just run tmux, fixing the TERM variable if requested. -- cgit v1.2.3-70-g09d2 From 51bf9fc2def19f1d3059c15059df21ddddb518fd Mon Sep 17 00:00:00 2001 From: Pandu E POLUAN Date: Wed, 28 Feb 2024 16:52:09 +0700 Subject: feat(tmux): prioritize `tmux` terminfo (#12243) Co-authored-by: Carlo Sala --- plugins/tmux/README.md | 32 ++++++++++++++++---------------- plugins/tmux/tmux.plugin.zsh | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index a253457f2..50f8b2c2f 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -1,7 +1,7 @@ # tmux -This plugin provides aliases for [tmux](https://tmux.github.io/), the terminal multiplexer. -To use it add `tmux` to the plugins array in your zshrc file. +This plugin provides aliases for [tmux](https://tmux.github.io/), the terminal multiplexer. To use it add +`tmux` to the plugins array in your zshrc file. ```zsh plugins=(... tmux) @@ -29,17 +29,17 @@ The plugin also supports the following: ## Configuration Variables -| Variable | Description | -| ----------------------------------- | ------------------------------------------------------------------------------------------- | -| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | -| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | -| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | -| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | -| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | -| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | -| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | -| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | -| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | -| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | -| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | -| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | +| Variable | Description | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------- | +| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | +| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | +| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | +| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | +| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | +| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | +| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) | +| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) | +| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | +| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 0ecb0a5b5..09e326344 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -20,13 +20,21 @@ fi # Set '-CC' option for iTerm2 tmux integration : ${ZSH_TMUX_ITERM2:=false} # The TERM to use for non-256 color terminals. -# Tmux states this should be screen, but you may need to change it on +# Tmux states this should be tmux|screen, but you may need to change it on # systems without the proper terminfo -: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +if [[ -e /usr/share/terminfo/t/tmux ]]; then + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=tmux} +else + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +fi # The TERM to use for 256 color terminals. -# Tmux states this should be screen-256color, but you may need to change it on +# Tmux states this should be (tmux|screen)-256color, but you may need to change it on # systems without the proper terminfo -: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +if [[ -e /usr/share/terminfo/t/tmux-256color ]]; then + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=tmux-256color} +else + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +fi # Set the configuration path if [[ -e $HOME/.tmux.conf ]]; then : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} -- cgit v1.2.3-70-g09d2 From 65b23a3328bfd7ddf3234de4538fa7c3e9644491 Mon Sep 17 00:00:00 2001 From: Jonathan De Troye Date: Thu, 29 Feb 2024 13:05:54 -0500 Subject: fix(tmux): do not pass empty flags to aliases (#12232) This enables compatibility with tmux >3.3a Co-authored-by: Carlo Sala --- plugins/tmux/tmux.plugin.zsh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 09e326344..436e2671d 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -47,14 +47,27 @@ fi : ${ZSH_TMUX_UNICODE:=false} # ALIASES -alias ta='tmux attach -t' -alias tad='tmux attach -d -t' -alias ts='tmux new-session -s' -alias tl='tmux list-sessions' +function _build_tmux_alias { + eval "function $1 { + if [[ -z \$1 ]] || [[ \${1::1} == '-' ]]; then + tmux $2 \"\$@\" + else + tmux $2 $3 \"\$@\" + fi + }" +} + alias tksv='tmux kill-server' -alias tkss='tmux kill-session -t' +alias tl='tmux list-sessions' alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG' +_build_tmux_alias "ta" "attach" "-t" +_build_tmux_alias "tad" "attach -d" "-t" +_build_tmux_alias "ts" "new-session" "-s" +_build_tmux_alias "tkss" "kill-session" "-t" + +unfunction _build_tmux_alias + # Determine if the terminal supports 256 colors if [[ $terminfo[colors] == 256 ]]; then export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR -- cgit v1.2.3-70-g09d2 From 0008534147a28eeeea52cfd92154ae2e801678ae Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Fri, 1 Mar 2024 16:44:20 +0100 Subject: fix(tmux): regression with detached sessions See https://github.com/ohmyzsh/ohmyzsh/pull/12242#issuecomment-1973236605 --- plugins/tmux/tmux.plugin.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 436e2671d..11550d687 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -100,11 +100,13 @@ function _zsh_tmux_plugin_run() { [[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC) [[ "$ZSH_TMUX_UNICODE" == "true" ]] && tmux_cmd+=(-u) + local _detached="" + [[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d" # Try to connect to an existing session. if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach ${ZSH_TMUX_DETACHED:+"-d"} -t $ZSH_TMUX_DEFAULT_SESSION_NAME + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t $ZSH_TMUX_DEFAULT_SESSION_NAME else - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach ${ZSH_TMUX_DETACHED:+"-d"} + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached fi # If failed, just run tmux, fixing the TERM variable if requested. -- cgit v1.2.3-70-g09d2 From 2c62584b8389cb9510c12f7c28b5ca7970619277 Mon Sep 17 00:00:00 2001 From: 张天泽 <35888946+zhangtianze1997@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:12:34 +0800 Subject: fix(tmux): use full offset parameter (#12249) --- plugins/tmux/tmux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 11550d687..791592d8f 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -49,7 +49,7 @@ fi # ALIASES function _build_tmux_alias { eval "function $1 { - if [[ -z \$1 ]] || [[ \${1::1} == '-' ]]; then + if [[ -z \$1 ]] || [[ \${1:0:1} == '-' ]]; then tmux $2 \"\$@\" else tmux $2 $3 \"\$@\" -- cgit v1.2.3-70-g09d2 From b26000d1685fa61bddddea42e2a606b2a0d64e25 Mon Sep 17 00:00:00 2001 From: Jhon Pedroza Date: Tue, 16 Apr 2024 02:52:12 -0500 Subject: feat(tmux): sessions named as current dir (#12351) --- plugins/tmux/README.md | 1 + plugins/tmux/tmux.plugin.zsh | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 50f8b2c2f..09952a9f5 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -37,6 +37,7 @@ The plugin also supports the following: | `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | | `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | | `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| `ZSH_TMUX_AUTONAME_SESSION` | Automatically name new sessions based on the basename of `$PWD` (default: `false`) | | `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | | `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | | `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 791592d8f..f65598358 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -13,6 +13,8 @@ fi : ${ZSH_TMUX_AUTOCONNECT:=true} # Automatically close the terminal when tmux exits : ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART} +# Automatically name the new session based on the basename of PWD +: ${ZSH_TMUX_AUTONAME_SESSION:=false} # Set term to screen or screen-256color based on current terminal support : ${ZSH_TMUX_DETACHED:=false} # Set detached mode @@ -102,9 +104,22 @@ function _zsh_tmux_plugin_run() { local _detached="" [[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d" + + local session_name + if [[ "$ZSH_TMUX_AUTONAME_SESSION" == "true" ]]; then + # Name the session after the basename of the current directory + session_name=${PWD##*/} + # If the current directory is the home directory, name it 'HOME' + [[ "$PWD" == "$HOME" ]] && session_name="HOME" + # If the current directory is the root directory, name it 'ROOT' + [[ "$PWD" == "/" ]] && session_name="ROOT" + else + session_name="$ZSH_TMUX_DEFAULT_SESSION_NAME" + fi + # Try to connect to an existing session. - if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t $ZSH_TMUX_DEFAULT_SESSION_NAME + if [[ -n "$session_name" ]]; then + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t "$session_name" else [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached fi @@ -116,8 +131,9 @@ function _zsh_tmux_plugin_run() { elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then tmux_cmd+=(-f "$ZSH_TMUX_CONFIG") fi - if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - $tmux_cmd new-session -s $ZSH_TMUX_DEFAULT_SESSION_NAME + + if [[ -n "$session_name" ]]; then + $tmux_cmd new-session -s "$session_name" else $tmux_cmd new-session fi -- cgit v1.2.3-70-g09d2 From 56afe7b3685be8a1ddef25a742016dc76c0a5f8f Mon Sep 17 00:00:00 2001 From: MoetaYuko Date: Mon, 3 Jun 2024 18:53:27 +0800 Subject: fix(tmux): add completion for alias functions (#12468) --- plugins/tmux/tmux.plugin.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index f65598358..399de1ccc 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -57,6 +57,19 @@ function _build_tmux_alias { tmux $2 $3 \"\$@\" fi }" + + local f s + f="_omz_tmux_alias_${1}" + s=(${(z)2}) + + eval "function ${f}() { + shift words; + words=(tmux ${@:2} \$words); + ((CURRENT+=${#s[@]}+1)) + _tmux + }" + + compdef "$f" "$1" } alias tksv='tmux kill-server' -- cgit v1.2.3-70-g09d2 From 379e974d2b54bcc7de0f1787a592957031616559 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 15 Jul 2024 18:45:46 +0200 Subject: fix(tmux): do not conflict with `rcExpandParam` Closes #12506 --- plugins/tmux/tmux.plugin.zsh | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 399de1ccc..51cc7d6a5 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -50,6 +50,7 @@ fi # ALIASES function _build_tmux_alias { + setopt localoptions no_rc_expand_param eval "function $1 { if [[ -z \$1 ]] || [[ \${1:0:1} == '-' ]]; then tmux $2 \"\$@\" -- cgit v1.2.3-70-g09d2 From d26c4a276610445670fb71d415804625cebd7ccd Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 15 Aug 2024 16:26:46 +0200 Subject: chore(tmux): add link to iTerm2 integration docs --- plugins/tmux/README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 09952a9f5..28ad3558a 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -29,18 +29,18 @@ The plugin also supports the following: ## Configuration Variables -| Variable | Description | -| ----------------------------------- | ----------------------------------------------------------------------------------------------------------- | -| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | -| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | -| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | -| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | -| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | -| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | -| `ZSH_TMUX_AUTONAME_SESSION` | Automatically name new sessions based on the basename of `$PWD` (default: `false`) | -| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | -| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | -| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) | -| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) | -| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | -| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | +| Variable | Description | +| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | +| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | +| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | +| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | +| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| `ZSH_TMUX_AUTONAME_SESSION` | Automatically name new sessions based on the basename of `$PWD` (default: `false`) | +| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | +| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | +| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) | +| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) | +| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for [iTerm2 tmux integration](https://iterm2.com/documentation-tmux-integration.html) (default: `false`) | +| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | -- cgit v1.2.3-70-g09d2 From ec07c79d7ef9f30d4f7aef7eb54b605cd78bfb3d Mon Sep 17 00:00:00 2001 From: Xin Li Date: Thu, 20 Mar 2025 12:25:40 -0700 Subject: feat(tmux): refresh global environments automatically (#5282) --- plugins/tmux/tmux.plugin.zsh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 51cc7d6a5..f6de9166f 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -15,6 +15,8 @@ fi : ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART} # Automatically name the new session based on the basename of PWD : ${ZSH_TMUX_AUTONAME_SESSION:=false} +# Automatically pick up tmux environments +: ${ZSH_TMUX_AUTOREFRESH:=true} # Set term to screen or screen-256color based on current terminal support : ${ZSH_TMUX_DETACHED:=false} # Set detached mode @@ -158,6 +160,15 @@ function _zsh_tmux_plugin_run() { fi } +# Refresh tmux environment variables. +function _zsh_tmux_plugin_preexec() +{ + local -a tmux_cmd + tmux_cmd=(command tmux) + + eval $($tmux_cmd show-environment -s) +} + # Use the completions for tmux for our function compdef _tmux _zsh_tmux_plugin_run # Alias tmux to our wrapper function. @@ -184,3 +195,9 @@ if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z _zsh_tmux_plugin_run fi fi + +# Automatically refresh tmux environments if tmux is running. +if [[ -n "$TMUX" && "$ZSH_TMUX_AUTOREFRESH" == "true" ]] && tmux ls >/dev/null 2>/dev/null; then + autoload -U add-zsh-hook + add-zsh-hook preexec _zsh_tmux_plugin_preexec +fi -- cgit v1.2.3-70-g09d2 From 0c8c7bf2a8efa66b504d17e3b56881925a580b40 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 20 Mar 2025 20:23:47 +0100 Subject: docs(tmux): add note to README for #5282 --- plugins/tmux/README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 28ad3558a..53607b8ad 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -31,6 +31,7 @@ The plugin also supports the following: | Variable | Description | | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `ZSH_TMUX_AUTOREFRESH` | Automatically refresh global environments (default: `true`) | | `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | | `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | | `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | -- cgit v1.2.3-70-g09d2 From eeaf9f89b0e8b10a02f16cb6cdd93779c28eb2ea Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 24 Mar 2025 20:52:31 +0100 Subject: fix(tmux): disable AUTOREFRESH by default (#13034) --- plugins/tmux/README.md | 2 +- plugins/tmux/tmux.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 53607b8ad..39c57f846 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -31,7 +31,7 @@ The plugin also supports the following: | Variable | Description | | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -| `ZSH_TMUX_AUTOREFRESH` | Automatically refresh global environments (default: `true`) | +| `ZSH_TMUX_AUTOREFRESH` | Automatically refresh global environments (default: `false`) | | `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | | `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | | `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index f6de9166f..d2729ec09 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -16,7 +16,7 @@ fi # Automatically name the new session based on the basename of PWD : ${ZSH_TMUX_AUTONAME_SESSION:=false} # Automatically pick up tmux environments -: ${ZSH_TMUX_AUTOREFRESH:=true} +: ${ZSH_TMUX_AUTOREFRESH:=false} # Set term to screen or screen-256color based on current terminal support : ${ZSH_TMUX_DETACHED:=false} # Set detached mode -- cgit v1.2.3-70-g09d2 From ff97957f1ccb33b1c1c27e47e2e24789ce2ae33f Mon Sep 17 00:00:00 2001 From: Bacluc Date: Mon, 21 Jul 2025 18:37:09 +0200 Subject: feat(tmux): avoid autostart inside `zed` editor (#13220) --- plugins/tmux/tmux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/tmux') diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index d2729ec09..4c184c2d0 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -188,7 +188,7 @@ function _tmux_directory_session() { alias tds=_tmux_directory_session # Autostart if not already in tmux and enabled. -if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then +if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" && -z "$ZED_TERM" ]]; 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 -- cgit v1.2.3-70-g09d2 From 0f45f82c0afdcaf71b193e349d01c069a3fb9de7 Mon Sep 17 00:00:00 2001 From: "Daniel R. Neal" Date: Mon, 22 Dec 2025 04:31:21 -0800 Subject: feat(tmux): add 'to' alias for session attachment (#13479) --- plugins/tmux/README.md | 1 + plugins/tmux/tmux.plugin.zsh | 1 + 2 files changed, 2 insertions(+) (limited to 'plugins/tmux') diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 39c57f846..aaa81aa17 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -23,6 +23,7 @@ The plugin also supports the following: | `tkss` | tmux kill-session -t | Terminate named running tmux session | | `tksv` | tmux kill-server | Terminate all running tmux sessions | | `tl` | tmux list-sessions | Displays a list of running tmux sessions | +| `to` | tmux new-session -A -s | Create or attach to a named tmux session | | `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session | | `tmuxconf` | `$EDITOR $ZSH_TMUX_CONFIG` | Open .tmux.conf file with an editor | | `ts` | tmux new-session -s | Create a new named tmux session | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 4c184c2d0..b1d97e98f 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -81,6 +81,7 @@ alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG' _build_tmux_alias "ta" "attach" "-t" _build_tmux_alias "tad" "attach -d" "-t" +_build_tmux_alias "to" "new-session -A" "-s" _build_tmux_alias "ts" "new-session" "-s" _build_tmux_alias "tkss" "kill-session" "-t" -- cgit v1.2.3-70-g09d2