Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable auto-start for multiplexers with SSH #292

Conversation

ColinHebert
Copy link
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

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
@sorin-ionescu
Copy link
Owner

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

@ColinHebert
Copy link
Contributor Author

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.)

@sorin-ionescu
Copy link
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.

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@neersighted
Copy link
Contributor

👍

@gdiscry
Copy link
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.

@ColinHebert
Copy link
Contributor Author

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?

@gdiscry
Copy link
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

@sorin-ionescu
Copy link
Owner

Fixed in 07686fa.

@ColinHebert ColinHebert deleted the revision/multiplex-auto-start branch April 18, 2014 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants