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

mintty + wsl.exe + tmux: resizing tmux pane with mouse not working #1238

Open
yunwu-jnpr opened this issue Oct 13, 2023 · 10 comments
Open

mintty + wsl.exe + tmux: resizing tmux pane with mouse not working #1238

yunwu-jnpr opened this issue Oct 13, 2023 · 10 comments

Comments

@yunwu-jnpr
Copy link

  1. If I use mintty to run wsl.exe then run tmux there (i.e. mintty.exe -e wsl -- tmux in short), then resizing tmux pane with mouse does not work.
    mintty_plus_wsl_plus_tmux__having_problem

  2. But if I run wsl.exe in cmd and run tmux there, then no problem.
    cmd_plus_wsl_plus_tmux__no_problem

  3. If I use mintty to ssh WSL and run tmux there, then also no problem.
    mintty_ssh_wsl_and_run_tmux__no_problem

@mintty
Copy link
Owner

mintty commented Oct 13, 2023

Using wsl.exe imposes severe limitations on terminal function because wsl.exe has its own idea of what a terminal could be.
That's why the wsltty project was created.
Using ssh is an interesting alternative. How do you start WSL in this case and how do you determine the IP to use?

@yunwu-jnpr
Copy link
Author

yunwu-jnpr commented Oct 13, 2023

@mintty Thanks for pointing out wsltty to me, just aware of it. Let me try if that fix the problem.

For your question how to start WSL, not sure if this is what you were asking, but I just start it by running wsl command in either cmd or mintty. I can close cmd or mintty window and run wsl again in another window.

To determine WSL IP address, I just use 127.0.0.1, since I have set localhostForwarding=true in my C:\Users\<user>\.wslconfig. See Advanced settings configuration in WSL on Microsoft website. Alternatively, I also configure a static IP address for my WSL by configuring a bootup script in WSL /etc/wsl.conf > [boot] section > command=<a_script> (see boot-settings section on the same page), so I can also use that IP address if I want.

@yunwu-jnpr
Copy link
Author

yunwu-jnpr commented Oct 13, 2023

I tried wsltty already. It fixes the tmux pane resizing problem indeed, however when running tmux a benefit mintty provides will be lost -- if you run ls command then press Ctrl key and hover mouse onto a file listed by ls command, then the file becomes a link, and you can click the link so mintty launches an external application (e.g. a text editor) to open it. This feature still works for mintty + wsl.exe (I spent some effort and figured out how to correctly pass the file path to the external text editor). But with wsltty, or mintty + ssh WSL, this feature does not work.

So I probably will continue using mintty + wsl.exe, and switch to either wsltty or mintty + ssh WSL when I need tmux + panes.

Thanks!

(If the tmux pane resizing issue under mintty + wsl.exe is caused by wsl.exe instead of mintty, then we can close this ticket. Thanks very much anyway!)

@ak2
Copy link
Contributor

ak2 commented Oct 17, 2023

I use ssh to connect to WSL2 on localhost as well, with a small script in shell:startup to start a hidden persistent wsl session, as unfortunately ssh sessions don't keep it alive.

wsl.vbs:

set ws=wscript.CreateObject("wscript.shell")
ws.run "wsl sleep infinity", 0

It's the , 0 that hides it.

Relative file links in WSL sessions can be made to work by telling mintty what your working directory is in terms of the wsl$ mount point that WSL creates for your distribution, using control sequence OSC 7. For example, by adding it to the PS1 setting:

PS1+='\e]7;//wsl\$/Ubuntu$PWD\a'

This works with wsltty as well. Absolute paths and those starting with ~ won't work though.

@mintty
Copy link
Owner

mintty commented Oct 17, 2023

Unfortunately, there are more prerequisites to using ssh, so I don't think it can be used reliably in a package for WSL connectivity:

  • sshd needs to be installed in each WSL distribution (Ubuntu has it by default, Debian and others don't)
  • sshd needs to be configured and launched
  • the IP address of each WSL distribution needs to be known

@yunwu-jnpr
Copy link
Author

unfortunately ssh sessions don't keep it alive

@ak2 have you tried ServerAliveInterval and ServerAliveCountMax SSH options?
I have ServerAliveInterval 20 and ServerAliveCountMax 3 in my /c/Users/<user>/.ssh/config and I never had a problem.

the IP address of each WSL distribution needs to be known

@mintty Not really. You can use 127.0.0.1 as I said. The other 2, right, but I think it is pretty simple.

@ak2
Copy link
Contributor

ak2 commented Oct 18, 2023

sshd staying alive isn't an issue, but WSL itself shuts down after 8 seconds if there isn't a wsl.exe session, even if an ssh session is open.

@mintty
Copy link
Owner

mintty commented Oct 18, 2023

You can use 127.0.0.1 as I said.

If you have multiple WSL distributions running, it will not be possible to reach them by the same IP.

The other 2, right, but I think it is pretty simple.

For a WSL frontend (similar to wsltty), the issue is to get this done automatically, on-the-fly.
First, if you find sshd not to be installed, you'd need to install it, using different package managers, using sudo (and you'll be asked for a password). Then, running sshd fails for example with "Missing privilege separation directory: /run/sshd". This is all practically untractable.

@yunwu-jnpr
Copy link
Author

I see your point. Thanks, @mintty .

@mintty
Copy link
Owner

mintty commented Oct 19, 2023

I have an idea to create a new "bridge" that would be resilient against changes in the WSL system by using wsl.exe.
In order to make pty I/O transparent, escape sequences would be "tunneled" through virtual normal character I/O.
I have a prototype already, handling output only so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants