Help with setting Cygwin's Emacs W32 TRAMP to WSL 1
Oleksandr Gavenko
gavenkoa@gmail.com
Thu Nov 26 15:18:37 GMT 2020
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.
More information about the Cygwin
mailing list