WSL & VSCode: Feeling at $home

In my previous blog, the plugin used to be able to modify files in the WSL filesystem without corruption was allowing only 1 file to be modified and “seen” in VSCode.
I’m glad to say that I finally found another plugin that not only provides the same SSH support (avoiding files corruption as stated above) but also provides a more complete “dev experience”.

Before we start, there is 2 prerequisites for this solution to work:

  • You should have a working OpenSSH server in your WSL environment.
    There is quite a lot of help or guides in Internet, but so far the “full solution” that is working all the time for me is the answer of this post
  • The VSCode console should be your WSL shell instead of Powershell (not mandatory, but more user friendly).
    You can change your user-settings (CTRL+,) with the following line for Ubuntu flavour:

    “terminal.integrated.shell.windows”: “C:\\Users\\<Your Username>\\AppData\\Local\\Microsoft\\WindowsApps\\ubuntu.exe”

Here is a quick how-to for the setup:

  1. Install VSCode and/or VSCode-Insiders (used for my demo)
  2. Install the plugin “FTP-Simple”
  3. Open the command bar (CTRL+SHIFT+P) and search for ftp-simple: config
  4. Create a first basic configuration just to ensure everything is working fine
  5. Open the command bar (CTRL+SHIFT+P) and search for ftp-simple: Remote directory to Workspace
  6. Choose your connection according to the name you provided in step 4
  7. [Optional] If you didn’t insert the password, type the password to the WSL account
  8. Choose from where the initial path should be open
  9. The workspace should be now open with the files and directories from the path you provided in step 4
  10. Open the terminal in VSCode
  11. Try changing content from Code or directly from the Console

Last (random) comments

  • This solution does not work with a separated terminal opened. The Workspace of VSCode keeps the SFTP connection alive, that’s what allow us to directly modify the files without having a new VSCode window being open
  • Your initial directory is the new ‘/’. You can think of it as a ‘chroot’. This means that if you try to open a file that is ‘below’ your initial directory, it will not work
  • Microsoft is working hard on bringing full interopability between WSL and Windows applications (filesystem included). So consider this post to be obsolete in the (near?) future.
  • The SSH solution is not my idea and it’s just an adaptation of Microsoft own solution for C++ and WSL.

Happy coding in your brand new WSL-VSCode environment.

WSL: Edit files remotely

So, after the (very) impressive demo by @richturn_ms during the Windows Developer Day – Creators Update, for the ones following WSL since some time now (if not from the beginning), there was this part that must have triggered the “wow” effect.

Now, I’m by no means what you can call a developer. Matter fact, I’m not a SysAdmin neither, just a simple hobbyist who likes to come with “special” ideas.

Back to our topic, after the “wow” effect faded away, I scratched my head a little bit as Rich was showing something that was normally forbidden!
Or was he? the way he performed the demo, was actually the “correct” way: from one OS to another using a standard protocol (SSH).

After some research, I found also a way for the ones of us that do not code in C++, however would like to modify files, directly from the WSL filesystem in the “correct” way also with VSCode (however, I guess other editors will also be able to apply this method).
So for the ones of you, who would like to open/create/update files with VSCode, just follow this small steps:

  1. Install Remote VSCode extension
  2. Edit your “User Settings” to enable the server to start automatically
  3. Bypass all the “SSH Tunneling” part, it will not be needed in our case
  4. Install Rmate for Bash (just perform the Quick Install commands)
  5. From WSL, run $ rmate -H localhost mytextfile.txt
  6. Save your changes, and confirm that the change has been correctly applied:
    • $ ll mytextfile.txt
    • $ cat mytextfile.txt

And that’s all, this should allow you to edit single files when following howtos in Internet (think Go, Nodejs, etc..).

>>> Nunix out <<<