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

tmux fails to start in local session #5132

Closed
kasper93 opened this issue Mar 26, 2020 · 18 comments
Closed

tmux fails to start in local session #5132

kasper93 opened this issue Mar 26, 2020 · 18 comments
Labels
Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.

Comments

@kasper93
Copy link
Contributor

kasper93 commented Mar 26, 2020

Environment

Windows 10.0.18363.0
tmux/tmux@f986539
WT @ 31efd69
Fully updated Cygwin as of 2020-03-26
Fully updated MSYS2 as of 2020-03-26

Steps to reproduce

  1. Run tmux

Expected behavior

tmux works

Actual behavior

tmux doesn't work

open terminal failed: not a terminal

Even more info

tmux works fine in

  • Cygwin@Mintty
  • MSYS2@Mintty
  • wsl
  • in ssh session
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Mar 26, 2020
@DHowett-MSFT
Copy link
Contributor

This is almost certainly a Cygwin runtime issue, as it’s failing to detect that the windows console host is attached. MinTTY is somewhat of a red herring- it has a special handshake that it does with Cygwin to assume terminal responsibility.

How are you launching your Cygwin profile?

@zadjii-msft zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Terminal The new Windows Terminal. labels Mar 26, 2020
@kasper93
Copy link
Contributor Author

For Cygwin I do (it is the same with bash):

"commandline": "C:/cygwin/bin/zsh.exe --login -i",

For MSYS2 (but it is Cygwin in disguise, so probably the same issue)

"commandline": "C:/MSYS/msys2_shell.cmd -defterm -no-start",

MinTTY is somewhat of a red herring- it has a special handshake that it does with Cygwin to assume terminal responsibility.

I understand that. I report here, because it would be nice to make it work in WT. But if you tell me that it need to be fixed on Cygwin side I guess I will redirect my request to them.

I did quick test with ConEmu and it has the same issue,

Ugh, I may have fire to fast with reporting this issue. It seems to be known issue.
cmderdev/cmder#453
alacritty/alacritty#1687
vercel/hyper#3608

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 26, 2020
@zadjii-msft
Copy link
Member

Thanks for following up with all those other issues! Looks like there's a pretty broad problem across terminal emulators on Windows. Do you know if there's actually an upstream bug on cygwin that's tracking this bug? I'd love to resolve this issue as a dup of the upstream one, but I want to make sure the diligence is done ☺️

@kasper93
Copy link
Contributor Author

I searched their ML and there seems to be no report about this specific issue. They don't have public bug tracker except mailing list. I will send them mail and see what they say.

@DHowett-MSFT
Copy link
Contributor

Since this looks pretty widespread, I'm gonna close out our copy of it. I'd definitely watch their mailing list, though, if I had a link to an ML archive for this report 😄

@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Mar 26, 2020
@kasper93
Copy link
Contributor Author

kasper93 commented May 14, 2020

After all I forgot to link here upstream report: https://sourceware.org/pipermail/cygwin/2020-March/244192.html Unfortunately, it went nowhere.

Sometimes you need to fix things by yourself... maybe when I feel the need for tmux again.

EDIT:

And explanation why this actually happens. https://cygwin.com/pipermail/cygwin/2020-May/244878.html

@sfzhi
Copy link

sfzhi commented Oct 13, 2021

For those who wish to use Windows Terminal + Cygwin + tmux, there is a workaround. It's not a very elegant one, but it appears to work.

Use the following command line in the Windows Terminal profile to start Cygwin:
C:\Cygwin\bin\sh.exe -lc "exec dtach -c /tmp/dtach-shell-$$ -Ez /bin/bash -i"

For this to work, dtach must be available in Cygwin. Unfortunately, Cygwin does not provide a binary package. Fortunately, dtach is very small and easy to build from source.

@mrjohannchang
Copy link

mrjohannchang commented Jan 10, 2022

Update

  1. Tested both ConEmu and Cmder, they do NOT have this issue. CC @kasper93
  2. Found 2 workarounds for Windows Terminal + MSYS2. CC @sfzhi
    1. Run tmux with this command: script -c tmux /dev/null. Source. CC @csdvrx
    2. windows-alt-sshd-msys2 CC: @rkitover

Related info

  1. Neovim doesn't work in Windows tmux nor MinTTY. mintty TUI neovim/neovim#6751

@PrashanthaTP
Copy link

PrashanthaTP commented Jan 14, 2022

Thank you so much @kasper93 @changyuheng @sfzhi for the research done and workarounds.
(I will always be thankful to windows terminal team).

TLDR : script.exe actually comes with util-linux package (msys2)

it may be already known, but commenting here just to save time for someone like me who is
searching for script.


I was wandering around the internet for months to get tmux
working in windows terminal (without wsl)

For anyone who wants to get windows terminal+ git bash+tmux without installing full package of cygwin or msys, we can do so by getting just tmux and script binary from msys packages (check once in the msys package page to verify if you already have its dependencies) and putting the so got files in respective folders of C:/Program Files/Git.

References :

script.exe : packages.msys2.org/package/util-linux
scrip.exe is actually in util-linux package : msys2/MINGW-packages#4497

@19945600523
Copy link

改为中文看不懂

@ducklin5
Copy link

ducklin5 commented Apr 2, 2022

If you are using the script screen or dtach workaround:

You'll need to export a couple of environmental variables in your .bashrc or .zshrc files to get your cool fonts working:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

@rkitover
Copy link
Contributor

rkitover commented Apr 2, 2022

Is anyone following up on fixing this in tmux itself?

@dgasaway
Copy link

1. Tested both [ConEmu ](https://github.com/Maximus5/ConEmu) and [Cmder](https://github.com/cmderdev/cmder), they do **NOT** have this issue. CC @kasper93

@changyuheng The statement that you tested ConEmu is pretty vague. I can say that if I try to run cygwin tmux from cmd.exe or cygwin bash in ConEmu, I get the same error as Windows Terminal. If I host a mintty session in ConEmu, I can run tmux, but then I'm running a different terminal emulator that is known to work.

@sventek-s
Copy link

sventek-s commented Nov 21, 2023

Thank you so much @kasper93 @changyuheng @sfzhi for the research done and workarounds. (I will always be thankful to windows terminal team).

TLDR : script.exe actually comes with util-linux package (msys2)

it may be already known, but commenting here just to save time for someone like me who is searching for script.

I was wandering around the internet for months to get tmux working in windows terminal (without wsl)

For anyone who wants to get windows terminal+ git bash+tmux without installing full package of cygwin or msys, we can do so by getting just tmux and script binary from msys packages (check once in the msys package page to verify if you already have its dependencies) and putting the so got files in respective folders of C:/Program Files/Git.

References :

script.exe : packages.msys2.org/package/util-linux scrip.exe is actually in util-linux package : msys2/MINGW-packages#4497

How exactly do you get it to work. I copied the binaries but still I get the open terminal failed: not a terminal on Git Bash

After you copy the binaries from C:\msys64\usr\bin to C:\Program Files\Git\usr\bin I used this alias stollen from netheril96

# placed it in ~/.bash_profile for both GIT BASH and MYSYS2
tmux() {
  # execute tmux with script
  TMUX="command tmux ${@}"
  SHELL=/usr/bin/bash script -qO /dev/null -c "eval $TMUX"
}

@martin-braun
Copy link

martin-braun commented Jan 25, 2024

The thing is still not fixed, wow.

On top of that, .tmux.conf doesn't work at all, and things need to load using the script method. Example: https://github.com/srouquette/msys2/blob/master/home/Syl/tmux.conf.sh

@ms-jpq
Copy link

ms-jpq commented Apr 4, 2024

Running tmux under script seems to be unacceptably slow, especially over SSH.

@lonelam
Copy link

lonelam commented Apr 24, 2024

Hi I just inspected the problem, I checked tmux source code and it seems that the key problem is tmux's tty detection failed on Windows Terminal, while the detection on mintty successed:
https://github.com/tmux/tmux/blob/master/tty.c#L107

So maybe the problem is, on windows, the cmd.exe or terminal.exe indeed not create a tty file to let the tmux to operate, and they are actually not a real terminal according to the following explanation:
https://unix.stackexchange.com/questions/4126/what-is-the-exact-difference-between-a-terminal-a-shell-a-tty-and-a-con

Maybe modifying msys2 could change this behavior? Or just not to use windows for development.

@rkitover
Copy link
Contributor

Hi, can anyone interested in this problem please try a tmux branch I'm working on, the police is not letting me test it.

It is the cygwin-support branch in my tmux fork here:

https://github.com/rkitover/tmux/tree/cygwin-support

To build do this in an MSYS shell on MSYS2:

git clone git@github.com:rkitover/tmux
cd tmux
git checkout cygwin-support
pacman -S --noconfirm gcc make bison autoconf automake libevent-devel ncurses-devel pkgconf
sh autogen.sh
./configure --prefix=/usr/local
make -j8

, this will create a tmux.exe in this directory.

rkitover added a commit to rkitover/MSYS2-packages that referenced this issue Jul 26, 2024
Add a patch to fix tmux failing to start in a local terminal session
when using Microsoft Terminal and other Windows terminals.

See:

microsoft/terminal#5132

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
rkitover added a commit to rkitover/MSYS2-packages that referenced this issue Jul 26, 2024
Add a patch to fix tmux failing to start in a local terminal session
when using Microsoft Terminal and other Windows terminals.

See:

microsoft/terminal#5132

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests