prezto/modules/tmux/README.md
Caleb Maclennan c3f1794510
Allow tmux session name to be passed as env var
For normal usage this change should be a NOOP. However it enables the
use case where the user might want to predefine what session gets
connected to when the shell is launched. Running `zsh` will still net
you a connection to the last used tmux session or a new one named
"zprezto" if none exists. However `env tmux_session=myname zsh` will
connect you specifically to a session called 'myname' including creating
it if it doesn't exist.

This is particularly useful in window managers where a key binding might
open a terminal with a predefined session or even show a list of current
sessions and open a new terminal connected to that session.

The default session name may still be set using zstyle as documented.
2019-06-20 10:30:11 +03:00

104 lines
2.9 KiB
Markdown

Tmux
====
Defines [tmux][1] aliases and provides for auto launching it at start-up.
Settings
--------
### Auto-Start
Starts a tmux session automatically when Zsh is launched.
To enable this feature when launching Zsh in a local terminal, add the
following line to *zpreztorc*:
```sh
zstyle ':prezto:module:tmux:auto-start' local 'yes'
```
To enable this feature when launching Zsh in a SSH connection, add the
following line to *zpreztorc*:
```sh
zstyle ':prezto:module:tmux:auto-start' remote 'yes'
```
In both cases, it will create a background session named _prezto_ if the tmux
server is not started.
You can change the default session name with:
```sh
zstyle ':prezto:module:tmux:session' name '<YOUR DEFAULT SESSION NAME>'
```
A session name may also be specified in an environment variable before ZSH runs.
```sh
env tmux_session='<SESSION NAME>' zsh
```
This can be useful for example to connect to a specific remote session
connecting via SSH (note that OpenSSH needs to be configured to pass on that
environment variable). It can also be used with window managers to set keybindings
that launch terminals with specific sessions.
With `auto-start` enabled, you may want to control how multiple sessions are
managed. The `destroy-unattached` option of tmux controls if the unattached
sessions must be kept alive, making sessions available for later use, configured
in *tmux.conf*:
```conf
set-option -g destroy-unattached [on | off]
```
#### iTerm2 Integration
[iTerm2][6] offers significant integration with tmux. This can be enabled by
adding the following line to *zpreztorc*:
```sh
zstyle ':prezto:module:tmux:iterm' integrate 'yes'
```
Read [iTerm2 and tmux Integration][7] for more information.
Aliases
-------
- `tmuxa` attaches or switches to a tmux session.
- `tmuxl` lists sessions managed by the tmux server.
Caveats
-------
On macOS, launching tmux can cause the error **launch_msg(...): Socket is not
connected** to be displayed, which can be fixed by installing
[reattach-to-user-namespace][3], available in [Homebrew][4], and adding the
following to *tmux.conf*:
```conf
set-option -g default-command "reattach-to-user-namespace -l $SHELL -l"
```
Furthermore, tmux is known to cause **kernel panics** on macOS. A discussion
about this and Prezto has already been [opened][2].
Authors
-------
*The authors of this module should be contacted via the [issue tracker][5].*
- [Sorin Ionescu](https://github.com/sorin-ionescu)
- [Colin Hebert](https://github.com/ColinHebert)
- [Georges Discry](https://github.com/gdiscry)
- [Xavier Cambar](https://github.com/xcambar)
[1]: http://tmux.sourceforge.net
[2]: https://github.com/sorin-ionescu/prezto/issues/62
[3]: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
[4]: https://github.com/mxcl/homebrew
[5]: https://github.com/sorin-ionescu/prezto/issues
[6]: http://iterm2.com
[7]: https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration