orbstack / orbstack

Fast, light, simple Docker containers & Linux machines for macOS
https://orbstack.dev
MIT License
5.1k stars 39 forks source link

launch VisualStudioCode in ssh mode instead of local filesystem mode when using code command #171

Open prabhah opened 1 year ago

prabhah commented 1 year ago

Is your feature request related to a problem? Please describe.

when I use "code" command on the linux virtual machine to open a directory in visual studio code(VSC), VSC opens the directory in local filesystem mode. such as:

on Linux virtual machine: cd /opt/test code .

VSC will be opened on MacOS, but the root path in VSC is ~/OrbStack/ubuntu/opt/test/

Describe the solution you'd like

Open the VSC in SSH mode, the correct path is ssh://orb:/opt/test

Describe alternatives you've considered VSC launched with "code" command does not work properly with my Golang project, I have to open VSC first, then use ssh mode to open the project directory manually.

Additional context Add any other context or screenshots about the feature request here.

JunJie-zhang-o commented 1 year ago

This is a great feature, just like using vscode in wsl.

piperswe commented 1 year ago

You can accomplish this by adding a code executable in your PATH with the following contents:

#!/usr/bin/env bash

dir="$(realpath "${1:-$(pwd)}")"
echo "Opening $dir in VSCode..."
exec mac code --folder-uri "vscode-remote://ssh-remote+$(whoami)@$(hostname)@orb$dir"
kdrag0n commented 1 year ago

Great solution! I did briefly try implementing this but it needs more testing with different code arguments.

FantasticRhythm commented 1 year ago

I could use ssh orb in the terminnal to log in the machine, but when I use Remote-ssh in VScode, something goes wrong It says

Could not establish connection to "orb": Could not resolve hostname.

image

And when I turn to connect Localhost:32222 ,it says

Could not establish connection to "localhost": Permission denied (publickey).

image
kdrag0n commented 1 year ago

I could use ssh orb in the terminnal to log in the machine, but when I use Remote-ssh in VScode, something goes wrong It says

Could not establish connection to "orb": Could not resolve hostname.

image

And when I turn to connect Localhost:32222 ,it says

Could not establish connection to "localhost": Permission denied (publickey).

image

@FantasticRhythm That's not related to this issue. I've replied in #292.

hailelagi commented 6 months ago

thanks <3 @piperswe