All Projects → chvolkmann → code-connect

chvolkmann / code-connect

Licence: MIT license
Open a file in your locally running Visual Studio Code instance from arbitrary terminal connections.

Programming Languages

shell
77523 projects
python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to code-connect

vscode-importmagic
No description or website provided.
Stars: ✭ 35 (-20.45%)
Mutual labels:  visual-studio-code
vsc-material-theme-icons
Material Theme Icons, the most epic icons theme for Visual Studio Code and Material Theme.
Stars: ✭ 90 (+104.55%)
Mutual labels:  visual-studio-code
vscode-stylelint-plus
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint, support auto fix on save.
Stars: ✭ 32 (-27.27%)
Mutual labels:  visual-studio-code
unity-tools
A Visual Studio Code Extension to provide some tools for Unity development
Stars: ✭ 25 (-43.18%)
Mutual labels:  visual-studio-code
vscode-2077-theme
Cyberpunk 2077 inspired theme for visual studio code
Stars: ✭ 96 (+118.18%)
Mutual labels:  visual-studio-code
aylin-vscode-theme
🌌Aylin: a modern and minimal VS Code dark theme with bright colors
Stars: ✭ 17 (-61.36%)
Mutual labels:  visual-studio-code
firebase-firestore-snippets
Contains the snippet for both Firebase and Firestore in VS Code editor
Stars: ✭ 13 (-70.45%)
Mutual labels:  visual-studio-code
papyrus-lang
📜Advanced language tools for the Papyrus scripting language.
Stars: ✭ 65 (+47.73%)
Mutual labels:  visual-studio-code
Netlify
A VS Code extension that displays your Netlify build statuses and more!
Stars: ✭ 23 (-47.73%)
Mutual labels:  visual-studio-code
hadouken
C/C++ Project Development Environment (boilerplate)
Stars: ✭ 25 (-43.18%)
Mutual labels:  vscode-remote
VscOdooSnippets
Odoo Snippets for Visual Studio Code
Stars: ✭ 29 (-34.09%)
Mutual labels:  visual-studio-code
Lilac-Theme
A dark theme with pastel colours for Visual Studio Code.
Stars: ✭ 24 (-45.45%)
Mutual labels:  visual-studio-code
Wikitext-VSCode-Extension
A Visual Studio Code Extension that provides language support for Wikitext.
Stars: ✭ 50 (+13.64%)
Mutual labels:  visual-studio-code
vscode-goto-next-previous-member
Visual Studio Code Extension to navigate through the functions, variables, and classes using quick and easy key commands similar to functionality provided by IntelliJ IDEs and Resharper
Stars: ✭ 24 (-45.45%)
Mutual labels:  visual-studio-code
ocean-space
🌊 Deep oceanic blue Visual Studio Code theme
Stars: ✭ 35 (-20.45%)
Mutual labels:  visual-studio-code
kumux-colorscheme-engine
Kumux is the world's first dynamic circadian color scheme for code editors and other software.
Stars: ✭ 102 (+131.82%)
Mutual labels:  visual-studio-code
ssh-agent-inject
[Note: Not needed with VS Code anymore.] Forwards the host's ssh-agent into a Docker container on Windows and macOS hosts.
Stars: ✭ 20 (-54.55%)
Mutual labels:  vscode-remote
TypeGame
👾 Sokoban Game in Pure TypeScript Type System
Stars: ✭ 222 (+404.55%)
Mutual labels:  visual-studio-code
AutoBuildMarlin
Visual Studio Code extension to more easily build Marlin Firmware
Stars: ✭ 206 (+368.18%)
Mutual labels:  visual-studio-code
vscode-commit-message-editor
Edit commit messages in a convenient way.
Stars: ✭ 40 (-9.09%)
Mutual labels:  visual-studio-code

code-connect

GitHub release (latest SemVer)

Open a file in your locally running Visual Studio Code instance from arbitrary terminal connections.

Motivation

VS Code supports opening files with the terminal using code /path/to/file. While this is possible in WSL sessions and remote SSH sessions if the integrated terminal is used, it is currently not possible for arbitrary terminal sessions.

Say, you have just SSH'd into a remote server using your favorite terminal and would like to open a webserver config file in your local VS Code instance. So you type code nginx.conf, which doesn't work in this terminal. If you try to run code nginx.conf in the integrated terminal however, VS Code opens the file just fine.

The aim of this project is to make the code cli available to any terminal, not only to VS Code's integrated terminal.

Prerequisites

  • Linux - we make assumptions on where VS Code stores its data based on Linux

    Macs could also support everything out of the box, confirmation needed. Please don't hesitate to come into contact if you have any information to share.

  • Python 3

    Tested under Python 3.6 and Python 3.8, but should work fine in Python 3.5 or newer.

  • socat - used for pinging UNIX sockets

    apt-get install socat

Visual Studio Code Server

You need to set up the server component of VS Code on the machine before using this utility. For this, connect to your target in a remote SSH session.

Afterwards, you should have a folder .vscode-server in your home directory.

Installation

Fish

Installing

With fisher

fisher install chvolkmann/code-connect

This downloads code_connect.py along with two functions. See functions/code.fish and functions/code-connect.fish

You can autocomplete the repository name in subsequent commands, e.g. fisher update code<TAB>

Updating

fisher update chvolkmann/code-connect

Uninstalling

fisher remove chvolkmann/code-connect

Bash

Installing & Updating

With bash/install.sh

curl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/install.sh | bash

This downloads code_connect.py along with two scripts and sets up aliases in your .bashrc for you. See bash/code.sh and bash/code-connect.sh

Uninstalling

With bash/uninstall.sh

curl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/uninstall.sh | bash

Deletes the aliases from ~/.bashrc and removes the folder ~/.code-connect

Usage

Use code as you would normally!

If you have VS Code installed on your remote machine as well (i.e. a code executable already exists), you can use code for your local instance and code-connect for an IPC connected instance.

Usage: code [options][paths...]

To read from stdin, append '-' (e.g. 'ps aux | grep code | code -')

Options
  -d --diff <file> <file>           Compare two files with each other.
  -a --add <folder>                 Add folder(s) to the last active window.
  -g --goto <file:line[:character]> Open a file at the path on the specified line and character position.
  -n --new-window                   Force to open a new window.
  -r --reuse-window                 Force to open a file or folder in an already opened window.
  -w --wait                         Wait for the files to be closed before returning.
  -h --help                         Print usage.

Troubleshooting
  -v --version Print version.
  -s --status  Print process usage and diagnostics information.

Changelog

See CHANGELOG.md

How it works

VS Code Remote under the hood

VS Code uses datagram sockets to communicate between a terminal and the rendering window.

The integrated terminal as well as the WSL terminal spawn an IPC socket. You also create one when connecting through a remote SSH session. These sockets can be found in the folders of VS Code Server.

Each time you connect remotely, the VS Code client instructs the server to fetch the newest version of itself. All versions are stored by commit id in ~/.vscode-server/bin. code-connect uses the version that has been most recently accessed. The corresponding code executable can be found in ~/.vscode-server/bin/<commit-id>/bin/remote-cli/code.

A similar method is used to list all of VS Code's IPC sockets, which are located under /run/user/<userid>/vscode-ipc-<UUID>.sock, where <userid> is the current user's UID and <UUID> is a unique ID. VS Code does not seem to clean up all stale connections, so some of these sockets are active, some are not.

Thus the first socket that is listening and that was accessed within a timeframe of 4 hours by default is chosen.

VS Code communicates the presence of an active IPC connection with the environment variable VSCODE_IPC_HOOK_CLI which stores the path to the socket.

You can verify this by opening a connection to your remote machine. In one case, you use VS Code's integrated terminal. In the other case, you use any other terminal.

Run

echo $VSCODE_IPC_HOOK_CLI

which displays an output in the integrated terminal, but not on the other one.

In order, every socket is checked to see if it is listening. For this, the following snippet based on this answer on StackOverflow was used.

socat -u OPEN:/dev/null UNIX-CONNECT:/path/to/socket

This returns 0 if and only if there's something listening.

code-connect under the hood

The script code_connect.py performs all of the above steps and runs the VS Code code executable as a child process with VSCODE_IPC_HOOK_CLI set properly, making it a drop-in replacement for code.

When we already have a code executable available, we don't need to search for it ourselves using code_connect.py. So we introduce two more scripts:

  • code-connect
    Direct alias to code_connect.py
  • code
    Checks whether there is a code executable locally installed already and tries to use it if available. Otherwise, code-connect will be used.

Contributing

See CONTRIBUTING.md

Credit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].