mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.11k stars 104 forks source link

[MSYS] Ability to launch WSL from existing Mintty install? #271

Closed rashil2000 closed 3 years ago

rashil2000 commented 3 years ago

I use MSYS and the terminal Mintty that comes with it. However, as is well known, Mintty doesn't support running Windows commandline apps (like cmd, powershell). So I can't launch WSL from inside Mintty.

Question is, will I need to download and install WSLtty separately for WSL? Is there a way I can configure my already-installed Mintty to run WSL (possibly by using scripts/files from this repository)?

mintty commented 3 years ago

That is not correct. You can run e.g. cmd within mintty. You can also start a mintty window with full WSL support: mintty --WSL=, optionally selecting a WSL distribution with a parameter value. You can also configure a WSL session launcher item into your context menu, see https://github.com/mintty/mintty/wiki/Tips#supporting-linuxposix-subsystems.

mintty commented 3 years ago

However, you'd need to install wslbridge2 into your system to make this work. I'll check whether to improve documentation on how to do this.

Biswa96 commented 3 years ago

Mintty doesn't support running Windows commandline apps (like cmd, powershell).

mintty is a terminal emulator, so you can run any program there. But the question is will it work without any issue?

I use MSYS and the terminal Mintty that comes with it.

Do you mean msys2? If yes then you can run wsl.exe there. But before that, you have to set the global environment variable MSYS=enable_pcon to enable ConPTY feature.

But ConPTY does not support all characters (e.g. ♥♦♣♠). So, there are programs like socat, ssh, wslbridge, wslbridge2 etc.

rashil2000 commented 3 years ago

Hi! So I tried running mintty --WSL=arch-linux, but it threw the error Failed to run '/bin/wslbridge2': No such file or directory.

However, you'd need to install wslbridge2 into your system to make this work.

You're right, how do I do this?

rashil2000 commented 3 years ago

mintty is a terminal emulator, so you can run any program there. But the question is will it work without any issue?

Exactly my point, the programs are in PATH, so they will start, but the I/O would not be what we usually expect. Let me give some examples to show this:

  1. The first is ssh. I'm just pressing arrow keys, nothing else. The upper window is mintty /c/Windows/System32/OpenSSH/ssh.exe azureuser@104.211.92.154, notice the initial error Pseudo-terminal will not be allocated because stdin is not a terminal. Even the shell prompt isn't shown at all. The lower window is mintty /usr/bin/ssh azureuser@104.211.92.154, which is working as expected.

hmmm

  1. The second is cmd. Upper window is mintty /c/Windows/System32/cmd.exe, lower is normal cmd.exe. Here too the shell prompt is missing, and arrow keys are misbehaving:

hmm2

  1. This one is powershell. Upper window is mintty /c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe, lower is normal powershell.exe. Notice the explicit errors.

hmm3

  1. The problem with WSL is similar, nothing is shown at all, and arrow keys misbehave.
rashil2000 commented 3 years ago

Do you mean msys2? If yes then you can run wsl.exe there. But before that, you have to set the global environment variable MSYS=enable_pcon to enable ConPTY feature.

Setting the value to 'enable_pcon' seems to have solved the issue.

May I ask what additional stuff wslbridge is providing?

Biswa96 commented 3 years ago

May I ask what additional stuff wslbridge is providing?

wslbridge and walbridge2 just grab the buffer from WSL side and spit it to Windows side and vice versa. No extra processing in-between. But ConPTY does some.

rashil2000 commented 3 years ago

Is there a reason MSYS=enable_pcon is not set by default on MSys2/Mintty? Does it break some stuff?

mintty commented 3 years ago

You may ask them:) Actually, one reason might be this: Throughout cygwin 3.1.*, ConPTY support is enabled by default, not only for Windows programs, but always active, i.e. also for cygwin programs, which unfortunately has some performance impact on their terminal output. This shall be fixed with cygwin 3.2, with unknown release date though.

Biswa96 commented 3 years ago

Does it break some stuff?

Yes, it breaks some stuff. Here is the commit in msys2 which makes the ConPTY feature as opt-in https://github.com/msys2/msys2-runtime/commit/22ba7ac08035c470a3927fa53805bcdcdfe5fc21. Also if you search conpty in any msys2 packaging repository you could find related issues. Personally, I get some overlapping while building projects with mingw-w64-cmake in msys2/MINGW-packages.

Biswa96 commented 3 years ago

Speaking of the actual question here, I have added a wslbridge2 release compiled with msys2 https://github.com/Biswa96/wslbridge2/releases. Just download, extract, run wslbridge2.exe in msys2. ConPTY is NOT required.

rashil2000 commented 3 years ago

Does it break some stuff?

Yes, it breaks some stuff. Here is the commit in msys2 which makes the ConPTY feature as opt-in msys2/msys2-runtime@22ba7ac. Also if you search conpty in any msys2 packaging repository you could find related issues. Personally, I get some overlapping while building projects with mingw-w64-cmake in msys2/MINGW-packages.

Thanks for this. I noticed some issues with it too. Like, I ran mintty cmd then opened up neovim, and it had registered some keystrokes by itself (see bottom)

image

Speaking of the actual question here, I have added a wslbridge2 release compiled with msys2 https://github.com/Biswa96/wslbridge2/releases. Just download, extract, run wslbridge2.exe in msys2. ConPTY is NOT required.

Sure, I'll check it out!

mintty commented 3 years ago

... run wslbridge2.exe in msys2.

Or copy the two wslbridge2 binaries (frontend and backend) into your /bin directory to enable full WSL-related feature support via mintty --WSL.

rashil2000 commented 3 years ago

... run wslbridge2.exe in msys2.

Or copy the two wslbridge2 binaries (frontend and backend) into your /bin directory to enable full WSL-related feature support via mintty --WSL.

That's what I did, thanks!

So should I close this now?

mintty commented 3 years ago

Actually, the mintty wiki already describes how to set up wslbridge2 to support launching WSL in mintty from cygwin or MSYS2: https://github.com/mintty/mintty/wiki/Tips#manual-setup-of-wsl-terminal

rashil2000 commented 3 years ago

Just a quick unrelated question - this wsl bridge method works only for WSL, right? And not for linux systems through SSH?

Biswa96 commented 3 years ago

Here is a direct quote from actual wslbridge's README:

wslbridge is a Cygwin program that allows connecting to the WSL command-line environment over TCP sockets, as with ssh, but without the overhead of configuring an SSH server.

rashil2000 commented 3 years ago

Oh, okay, now it makes sense. Thanks!

mintty commented 3 years ago

For remote ssh, wslbridge2 is not needed; just run ssh.

rashil2000 commented 3 years ago

I had this doubt because SSH from mintty was also problematic, before I set MSYS=enable_pcon

mintty commented 3 years ago

You can also configure ssh shortcuts for the context menu session launcher and also for the taskbar icon as described in the manual.

rashil2000 commented 3 years ago

I've spent plenty of time customizing mintty (I absolutely love it for the sheer amount of SGR parameters it supports xD) - here's what I settled into:

Transparency=off
Font=RecMonoSemicasual NF
FontHeight=10
FontWeight=400
BoldAsFont=yes
BoldAsColour=no
Scrollbar=right
ConfirmExit=no
ThemeFile=google-light
Term=xterm-256color
BellType=0
TabBar=9
Icon=D:\Data\Pictures\Icons\bash.ico
SessionGeomSync=4
SessionCommands=Kali Linux:-i D:\Data\Pictures\Icons\kali-menu.ico wsl;Arch Linux:-i D:\Data\Pictures\Icons\archlinux.ico wsl -d arch-linux;Ubuntu - Azure:-i D:\Data\Pictures\Icons\ubuntuazure.ico ssh ubuntuazure;Ubuntu - OSBoxes:-i D:\Data\Pictures\Icons\Ubuntu.ico ssh ubuntuosboxes;
Columns=90
Rows=30
mintty commented 3 years ago

I'm considering to add an option to enforce enabling ConPTY support, for use in combination with your remote SessionCommands entries on MSYS2.

rashil2000 commented 3 years ago

Yes, that might be helpful. One thing to note here is that I don't have OpenSSH installed on Msys2; the session commands here are using the ssh executable from Windows\System32 side.

mintty commented 3 years ago

Released 3.4.5.

rashil2000 commented 1 year ago

Hi all!

Just wanted to follow up on this issue after this was posted: https://www.msys2.org/news/#2022-09-24-conpty-support-enabled-by-default

I still need to set MSYS=enable_pcon explicitly in order to avoid the issues mentioned in the recordings above. What seems to be the issue here? Do I need some specific versions of some packages?

mintty commented 1 year ago

Just speculating: I guess the changed default is only applied on fresh installation. You might ask them whether it can be switched during update.

rashil2000 commented 1 year ago

I guess the changed default is only applied on fresh installation.

Okay, I downloaded a fresh tar file of MSYS2, and it works fine there.

You might ask them whether it can be switched during update.

Where should I post this question?

mintty commented 1 year ago

You might ask them whether it can be switched during update.

Where should I post this question?

Don't know, look on their homepage.