Disable auto-start for multiplexers with SSH #292

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

Contributor

I was playing with SSH and ended up on my own machine (don't ask) which is for me, the only one using the auto-start option (tmux/screen).

The problem is that I ended up with a multiplexer session inside another multiplexer session which is really confusing (even more in my case, where the two sessions were actually the same...).


In general having a multiplexer inside another multiplexer is just plain bad, but when it comes to remote connections there is no way to tell if the user is already in a multiplexer or not.

I guess the best action against that, is disabling auto-start for remote connections by default.
Then the user will be able to start the multiplexer manually if he wants to.


I understand that some people only use a multiplexer on the server side (so, there is no way that the user could already be in a multiplexer), and want auto-start to work properly with a remote access.

I added a new option for screen and tmux forcing auto-start to work with remote connections:

zstyle ':prezto:module:tmux' remote 'yes'

This will allow auto-start for an SSH connection on a server.


The documentation and zpreztorc have been upgraded

@ColinHebert ColinHebert Disable auto-start for multiplexers with SSH
Do not automatically start multiplexers if the machine is access with a
remote connection (SSH).
This avoids having the 'remote' screen or tmux session embedded in the local
session
75682fb
Owner

Given that this is an extension of auto-start, shouldn't the style be zstyle ':prezto:module:tmux:auto-start' remote 'yes'?

Contributor

I was about to do that, but then I thought it would be better to change

zstyle ':prezto:module:tmux' auto-start 'yes'

into

zstyle ':prezto:module:tmux:auto-start' enable 'yes'

So I decided to leave it for now and get some input on which name would be the best.

(Just to be clear, it's for tmux and screen, zstyle ':prezto:module:screen' remote 'yes' will need to be modified too.)

Owner

If you add enable, you'd probably have to do the same to other zstyles since it's confusing for one to have enable while another does not.

I general, if the zstyle is not defined, it has been considered disabled, like git-info formats.

@sorin-ionescu sorin-ionescu commented on the diff Oct 3, 2012
modules/tmux/init.zsh
@@ -15,7 +15,8 @@ fi
# Auto Start
#
-if [[ -z "$TMUX" ]] && zstyle -t ':prezto:module:tmux' auto-start; then
+if ( [[ -z "$SSH_CLIENT" ]] || zstyle -t ':prezto:module:tmux' remote ) &&
+ ( [[ -z "$TMUX" ]] && zstyle -t ':prezto:module:tmux' auto-start ); then
sorin-ionescu
sorin-ionescu Oct 3, 2012 Owner

This if statement is a bit hard to read. It looks to me like it fails on localhost if remote is not set to true.

sorin-ionescu
sorin-ionescu Oct 3, 2012 Owner

I think I understood it after I translated it to something more readable.

( is-false "$_screen_is_on_remote" || is-true "$_screen_auto_start_on_remote" ) && ( is-false "$_screen_is_started" && is-true "$_screen_auto_start")
ColinHebert
ColinHebert Oct 4, 2012 Contributor

It's basically:

If we are not in a SSH (remote) session or if starting the multiplexer in a SSH (remote) session is enabled
and, if the multiplexer isn't started and if auto-start is enabled.

Contributor

👍

Contributor
gdiscry commented Jan 24, 2013

Good thing I didn't send a pull request before checking the issues.

I worked a bit on the same issue but the other way around. In my case the problem is that I want a multiplexer session when connecting with SSH but not when using a local terminal (or when using something like sudo -s). The reasoning is that I want my session to remain active if I get disconnected.

In order to do that, I tweaked the auto-startstyle to accept more options. The yes value works as usual and a session is always started:

zstyle ':prezto:module:tmux' auto-start 'yes'

I added a ssh option that starts a session only when connecting with SSH:

zstyle ':prezto:module:tmux' auto-start 'ssh'

As this issue is about another use case, I won't send the pull request. You can look at my code there: gdiscry/prezto@1ddc656.

Contributor

Hum that's actually a very good usecase. I usually have the tmux session started on my local machine and connect without tmux on my remote session, but it could very well be the case for someone else that tmux is started only when accessed through SSH (all of that still applies with screen).

Maybe we should have something along the lines of:

zstyle ':prezto:module:tmux' auto-start 'no'
zstyle ':prezto:module:tmux' auto-start 'ssh' (or 'remote' ?)
zstyle ':prezto:module:tmux' auto-start 'local'
zstyle ':prezto:module:tmux' auto-start 'always'

If we want to do some backward compatibility we could just say that 'yes' is the same thing as 'always'.

What do you think?

Contributor
gdiscry commented Jan 24, 2013

I was indeed thinking of something like

zstyle ':prezto:module:tmux' auto-start 'no'
zstyle ':prezto:module:tmux' auto-start 'remote' ('ssh')
zstyle ':prezto:module:tmux' auto-start 'local' ('no-ssh')
zstyle ':prezto:module:tmux' auto-start 'yes'

I prefer yesto always as it's a boolean value for zstyle and keeps compatibility with the current behaviour.

If I didn't make a mistake, it would work like this:

if [[ -z "$TMUX" ]] && ( zstyle -t ':prezto:module:tmux' auto-start \
    || [[ -n "$SSH_TTY" ]] && zstyle -m ':prezto:module:tmux' auto-start 'remote' \
    || [[ -z "$SSH_TTY" ]] && zstyle -m ':prezto:module:tmux' auto-start 'local' ); then

Edit: gdiscry/prezto@4ca8439

Owner

Fixed in 07686fa.

@ColinHebert ColinHebert deleted the ColinHebert:revision/multiplex-auto-start branch Apr 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment