code-connect: Open files in VS Code over remote terminal connections
Posted by Freemanium@reddit | linux | View on Reddit | 2 comments
I put this little thing together out of frustration while working with remote machines via SSH.
My usual workflow consists of connecting to a remote machine via SSH using my favorite terminal. Whenever I need to open a file in this terminal session, I can't simply run code nginx.conf as that would open a VS Code window on the remote machine. But I want to display the file in my local editor window without having to set up X11 or VNC. So I'm stuck with vim. Oof.
When using VS Code to establish a remote SSH session, the above works like a charm using the integrated terminal. The same goes for WSL sessions. Again, for other terminal sessions, this is not the case.
So I looked closer at how VS Code communicates between remote and client and came up with a repo based on an answer on StackOverflow. If you're interested in how it works, I've written a small summary in the README.
Meet code-connect
All you need to do is to source a script in your .bashrc or fish.config. This sets up an alias for code that
- picks the most recently accessed code binary
- finds the most recently accessed listening IPC socket
You're now free to run code . anywhere on your remote machine to attach to your locally running VS Code window!
Users of the fish shell also get the easy option to install through a plugin.
https://github.com/chvolkmann/code-connect
Hope it's helpful to you guys, comments and feedback are welcome!
Cyborg-2077@reddit
Just found out about this while running into the same problem, thanks for making this! I'm impressed how flawlessly this works, took literally 5 seconds to setup
arulrajnet@reddit
This is exactly what I want.
Is this `code-connect` still works?
Did you guys find any other better way.