diff --git a/modules/tmux/README.md b/modules/tmux/README.md index 68ba9d0..0e2f652 100644 --- a/modules/tmux/README.md +++ b/modules/tmux/README.md @@ -20,12 +20,15 @@ following line to *zpreztorc*: zstyle ':prezto:module:tmux:auto-start' remote 'yes' -In both cases, it will create a background session named _#Prezto_ and attach -every new shell to it. +In both cases, it will create a background session named _prezto_ if the tmux +server is not started. -To avoid keeping open sessions, this module sets `destroy-unattached off` on -the background session and `destroy-unattached on` on every other session -(global setting). +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*: + + set-option -g destroy-unattached [on | off] Aliases ------- @@ -41,7 +44,7 @@ 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*: - set-option -g default-command "reattach-to-user-namespace -l $SHELL -l" + set-option -g default-command "reattach-to-user-namespace -l $SHELL -l" Furthermore, tmux is known to cause **kernel panics** on Mac OS X. A discussion about this and Prezto has already been [opened][2]. @@ -54,6 +57,7 @@ Authors - [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 diff --git a/modules/tmux/init.zsh b/modules/tmux/init.zsh index bee24e4..c6c3626 100644 --- a/modules/tmux/init.zsh +++ b/modules/tmux/init.zsh @@ -5,6 +5,7 @@ # Sorin Ionescu # Colin Hebert # Georges Discry +# Xavier Cambar # # Return if requirements are not found. @@ -22,25 +23,16 @@ if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" ]] && ( \ ); then tmux_session='prezto' - if ! tmux has-session -t "$tmux_session" 2> /dev/null; then - # Ensure that tmux server is started. - tmux start-server - - # Disable the destruction of unattached sessions globally. - tmux set-option -g destroy-unattached off &> /dev/null - - # Create a new session. - tmux new-session -d -s "$tmux_session" - - # Disable the destruction of the new, unattached session. - tmux set-option -t "$tmux_session" destroy-unattached off &> /dev/null - - # Enable the destruction of unattached sessions globally to prevent - # an abundance of open, detached sessions. - tmux set-option -g destroy-unattached on &> /dev/null + # Create a first 'prezto' session if tmux is starting. + if ! tmux has-session 2> /dev/null; then + tmux \ + start-server \; \ + new-session -d -s "$tmux_session" \; \ + set-option -t "$tmux_session" destroy-unattached off &> /dev/null fi - exec tmux new-session -t "$tmux_session" + # Attach to the 'prezto' session or to the last session used. + exec tmux attach-session fi # diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 80f2a05..a54fdb0 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -152,4 +152,3 @@ zstyle ':prezto:module:prompt' theme 'sorin' # Auto start a session when Zsh is launched in a SSH connection. # zstyle ':prezto:module:tmux:auto-start' remote 'yes' -