How to change the default integrated terminal folder in remote wsl vscode

Viewed 1054

i'm currently having a really annoying problem since i ran windows repair on my PC. My wsl remote vscode for some reason that i couldn't find out in the net, isn't able to open the current folder in the terminal. Instead, it opens vscode appdata windows folder(/mnt/c/Users/Jonathan/AppData/Local/Programs/Microsoft VS Code), like in the images linked below:

my current workspace

open in integrated terminal result

My remote settings.json file:

{
  "go.autocompleteUnimportedPackages": true,
  "terminal.integrated.profiles.linux": {
    "bash": {
      "path": "bash",
      "icon": "terminal-bash",
      "cwd": "/home/jonathanr/Documents/workspace"
    },
    "zsh": {
      "path": "zsh"
    },
    "fish": {
      "path": "fish"
    },
    "tmux": {
      "path": "tmux",
      "icon": "terminal-tmux"
    },
    "pwsh": {
      "path": "pwsh",
      "icon": "terminal-powershell"
    }
  }
}

Thanks a lot for any help!

1 Answers

So, turns out I found the solution. To anyone who's struggling with this problem, the problem was (in my case at least) in one of the environment variables that vscode was running WSL with. It is called PRE_NAMESPACE_PWD. If you run WSL with debug enabled (to do this just go to the WSL remote extension settings and turn on the Remote WSL:Debug option). You'll notice the "env" options in WSL command with all environment variables listed there, and if you keep scrolling you'll notice two variables: PRE_NAMESPACE_PWD and PWD. In this problem, the PRE_NAMESPACE_PWD was pointing to the windows vscode folder instead of the current workspace folder in WSL and the PWD variable was using this folder. To summarize, I just exported this PRE_NAMESPACE_PWD variable with the value ${cwd} which is a command that gets the current workspace folder in my vscode. To do this, simply add this line to your remote Settings.json file:

"terminal.integrated.env.linux": {
    "PRE_NAMESPACE_PWD": "${cwd}"
  }

And that's it, now every time you click on "Open with integrated terminal" your terminal is going to open in the right workspace directory.

Related