DEV Community

Tim Apple for Vets Who Code

Posted on

Sharing your project folder with Windows and WSL

This is going to be short and sweet since it's not that complicated. The main goal is to operate in the same project folders whether you are operating within WSL or Windows itself. The side bonus is it's easier to keep your project folder backed up.

First thing, when I say project folder, what I am referring to is one folder I call Projects and I keep everything I'm working on in there. I do a lot of stuff that doesn't necessarily require me to be in the Linux Subsystem all the time, but I like to always work out of one directory whichever interface I'm in.

First off you need to make your Projects folder or whatever you would like to call it. Again, I like "Projects". I place it in my Windows user folder. It's a little more difficult navigating from within Windows to the subsystem. But from the subsystem to Windows is no problem. And there are some other benefits to keeping it on the Windows side.

Unless you have changed it, WSL usually defaults you to your Windows home directory instead of the Linux user directory.

Alt Text

So the first think we want to do is document that path..in mine it's /mnt/c/Users/timap we're just going to add our Projects folder to that path assuming you created it in your Windows Home. So, mine would be /mnt/c/Users/timap/Projects.

So what I do next is make an alias to my path in my .bashrc or .zshrc depending on which shell your using. The steps are the same.

cd - Brings me to my Linux home Directory.
nano .zshrc - Will open up my zsh config in the nano editor. You could also do nano .bashrc again if that was your shell of choice.

What I am going to do is goto the bottom of my config and create an alias, in my case using the work "projects" and I am going to have it point to that Windows home projects folder.

Alt Text

Then just ctrl + o to save and ctrl + x to exit. To reload your config you can just source .zshrc or source .bashrc depending on which one you were using.

So looking at the alias I made, now whenever I am in my Linux terminal I just type proj and bam! There I am. Also, when in a directory while using the subsystem you can type code . and it will open Visual Studio Code using that directory as a working directory.

So here are the two ways I work.

  1. I open VSCode and navigate to my project folder the old-fashioned way through Windows and get to work, but no access to the subsytem.
  2. I open up my Ubuntu install, type proj, the type code . and I'm doing the same as above but working through Linux.

The secondary benefit is I now sync that directory with pCloud. So I always have it backed up outside of just using git. Of course, it being Windows you could throw your projects folder in your Onedrive and accomplish the same effect.

Top comments (0)