public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Help with setting Cygwin's Emacs W32 TRAMP to WSL 1
@ 2020-11-26 15:18 Oleksandr Gavenko
  2020-11-26 15:24 ` Eliot Moss
  2020-11-26 18:42 ` Henry S. Thompson
  0 siblings, 2 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2020-11-26 15:18 UTC (permalink / raw)
  To: cygwin

I'm using Cygwin for two reasons: mintty + Emacs w32.

Nowadays WSL 1 has become important (vendors provide ready to work
.deb packages,
 I use: Ansible + Google Cloud SDK, if name any).

Still WSL 1 lacks UI and integrates less smoothly into my workflow
to replace Cygwin's amazing Emacs W32.

WSL1 files are "hidden" for regular access.

Emacs has TRAMP mode to access foreign environments:
https://www.gnu.org/software/tramp/

I tried to define configuration that should have allowed to access WSL 1
from Cygwin's Emacs via "wsl sh" jump (the way TRAMP support "su" &
"sudo" jumps):

* https://www.reddit.com/r/emacs/comments/jrkgmy/tramp_for_wsl_1_from_cygwin_emacsw32/
* https://github.com/microsoft/WSL/issues/6236
  - wsl.exe periodically sends control characters making impossible "piping"
  via interactive/terminal mode

The problem is that when Cygwin's Emacs invokes "wsl.exe" conhost or
wsl?? thinks
it is in a PTY mode and sends different "clearing" terminal escape
sequences (see WSL issue report).

I reproduce garbage with Elisp code:

(setq xxx (make-process :name "xxx" :buffer "xxx" :command '("wsl"
"echo" "OK") :connection-type 'pty))
(stop-process xxx)

Note that changing the last argument "pty" => "pipe" solves the problem,
but things are a bit complicated...

TRAMP mode has been implemented via call to "sh" by internal API "make-process".
And then TRAMP sends  "wsl ..." to the shell so WSL thinks it is in
PTY and I have no way
to influence that decision ((

I tried stupid tricks like passing everything related to "ws.exe" via
pipe to "cat":

  (with-eval-after-load 'tramp
    (setf (alist-get "wsl" tramp-methods nil nil #'equal)
          '((tramp-login-program "sh")
            (tramp-login-args (("-c") ("wsl") ("-u" "%u") ("-d" "%h")
("|" "cat")))
            (tramp-remote-shell "/bin/sh")
            (tramp-remote-shell-login ("-l"))
            (tramp-remote-shell-args ("-c"))
            (tramp-connection-timeout 10)
            (tramp-session-timeout 300))))

or define a  wrapper script that has "wsl ... | cat"  inside. Nothing helped.
Few experiments with Cygwin's Expect also failed as I forgot
everything about that obscure tech...

So I need to write some wrapper that will bidirectionally pipe to "wsl.exe"
putting wsl into piped instead TTY mode.

It can be that there is a ready solution.

If not please advise which API should I use to write such  a wrapper.

Should it be Cygwin's pipe/dup2/fork/execvp or popen?

Or should it be Windows native CreateChildProcess / WriteToPipe /
ReadFromPipe as here:
https://docs.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output

Please CC me in replies, I'll check the mail archive after a week to
not lose any responses.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-11-28 14:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 15:18 Help with setting Cygwin's Emacs W32 TRAMP to WSL 1 Oleksandr Gavenko
2020-11-26 15:24 ` Eliot Moss
2020-11-26 20:38   ` Oleksandr Gavenko
2020-11-27 18:12     ` Eliot Moss
2020-11-28 14:07       ` Oleksandr Gavenko
2020-11-26 18:42 ` Henry S. Thompson
2020-11-26 19:22   ` Oleksandr Gavenko
2020-11-26 20:02     ` Oleksandr Gavenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).