vagrant-tramp
vagrant-tramp copied to clipboard
Make it work under Windows
This mode works great, except it doesn't play nice under Microsoft Windows, even when a cygwin installation as been performed.
It would be great to make it work, as both Emacs and Vagrant are pretty much OS-agnostic solutions.
I'd be ready to give a hand, with my limited knowledge.
Thank you for offering, @p3r7. What can you tell me about how vagrant-tramp works under Windows?
If you're in a shell:
- does
vagrant global-status
work? - does
vagrant ssh
in a folder associated with a running Vagrant machine work? - does the
bin/vagrant-tramp-ssh
script work? (to invoke it, you use the name of a folder associated with a running Vagrant machine. So for example, if one such folder is/home/ryan/scratch
thenvagrant-tramp-ssh scratch
should log me into that machine.
I'm looking forward to getting this working on Windows. It would be nice to try it with the new Bash for Windows as soon as possible, too.
I just tried installing from melpa using windows and it fails creating the autoloads. It looks like the problem is executable-find
not finding the shell script: abbreviated backtrace
Debugger entered--Lisp error: (wrong-type-argument arrayp nil) replace-regexp-in-string("(\*)"" "\1\1\"" nil) shell-quote-argument(nil) byte-code("[removed]" [load-file-name buffer-file-name shell-quote-argument executable-find file-name-directory "bin/vagrant-tramp-ssh"] 4) ....
Simply removing the executable-find seems to work fine, is it necessary since there is only the one file in /bin anyhow?
No, that executable-find
doesn't seem necessary. I don't remember including it for any particular reason, so maybe I just threw it in there all like "oh yeah I'm totally finding an executable hurr durr"
Removing that makes the melpa install work fine, but I still couldn't get the script to work correctly using mingw port of bash -- not sure why exactly I was going to try to isolate the problem tomorrow and maybe implement in elisp so there would be no portability issues. All the command line vagrant stuff you mention above works the same on windows as far as I can tell.
Tramp is rather inflexible in how it invokes the connection program. If we use vagrant ssh
without a wrapper, it needs to be passed a hash id of a machine, which means that we would have to offer hash IDs as completions in Emacs. Which is not a great experience.
There are three ways I could think of to get around that:
- use a wrapper script, which as you point out carries potential portability issues
- submit a patch to Vagrant allowing people to globally identify a machine in human-readable format, similar to the scheme
vagrant-tramp
uses now. - submit a patch to Tramp which introduces an optional function that transforms the Tramp hostname to arguments for the connection program
I went with the first option since it's the one I could implement for myself without needing to get agreement from the Vagrant or Emacs upstream communities.
In the long term I think that either 2 or 3 are ultimately better options for portability and simplicity of vagrant-tramp
and similar tools. In the short term, I'm interested to see if we can find a way to make the wrapper script work on Windows.
What do you think?
Yea, having a solution without an additional wrapper script sounds best, but I can't offer a solution. I will try to look closely at the code and learn me some elisp when I can. I had to spend a while to understand your awk script, so I am not likely to be useful in improving your bash script. Perhaps, if you want the wrapper to work on windows as well there could be a parallel batch script? I don't know, if I come up with something I will post it.
Note that there's a new version of the wrapper script that I introduced in #31. The previous script gave problems on many platforms, not just Windows.
I've just tested the script vagrant-tramp-ssh
under cygwin bash, providing my runing VM name as an argument, and the script works fine.
@p3r7 thanks for testing that out. A couple more questions for you:
Is anything printed to the *Messages*
buffer when you try to use the vagrant
method to find a file?
Are you able to use Alt-xvagrant-tramp-term
to launch a terminal session?
I'm very pleased to discover that M-x term
works flawlessly on w32 emacs 25.0.92.1. I didn't know that! M-x vagrant-tramp-term
works as well!
Please note that I have a setup where cygwin's bin folders get added to emacs' PATH at startup, so that might be why I can launch a term window (see https://github.com/p3r7/emacs.d/blob/master/init/components/init-cygwin-integration.el for full implementation).
I don't have completion when I M-x find-file
/vagrant:
, but that might be due to a conflict with cygwin-mount plugin.
When I explicitely do a M-x find-file
/vagrant:trusty32:/
, a buffer /vagrant:root@trusty32:/ opens up, but it prints :
Tramp: Sending command ‘"c:/Users/jordan.besly/AppData/Roaming/.emacs.d/plugins/vagrant-tramp/bin/vagrant-tramp-ssh" trusty32 && exit || exit’
and a message telling that the OS failed to find any valid executable.
No additional information is available in the *Messages*
buffer.
Indeed, MS Windows searches for files with extensions sur as .exe, .bat ...
I guess we'd need a windows equivalent to script vagrant-tramp-ssh, or a wrapper around it that would call it via cygwin's bash.