You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
8
## [Unreleased]
9
+
9
10
Maybe your next idea?
11
+
12
+
## [0.3.0] - 2021-02-18
13
+
14
+
### Added
15
+
16
+
- bash uninstaller
17
+
18
+
### Changed
19
+
20
+
-`code-connect` is now not just one alias anymore, but two aliases.
21
+
22
+
- The `code-connect` alias is added functionality of this repo, it points to `code_connect.py`
23
+
- The `code` alias checks whether `code` is in the PATH and omits using `code-connect` in this case. This is useful for the integrated terminal as a `code` executable is injected by VS Code into the PATH. Thus, `code` should just run that existing executable, not `code-connect` instead.
24
+
25
+
See [#8](https://github.com/chvolkmann/code-connect/issues/8)
26
+
27
+
- bash installer is now fancy
28
+
- All bash-related files are now in the `bash/` folder
29
+
- All `code_connect.py` is now in the `bin/` folder
Copy file name to clipboardExpand all lines: README.md
+64-24Lines changed: 64 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,53 +8,84 @@ Open a file in your locally running Visual Studio Code instance from arbitrary t
8
8
9
9
VS Code supports opening files with the terminal using `code /path/to/file`. While this is possible in [WSL sessions](https://code.visualstudio.com/docs/remote/wsl) and [remote SSH sessions](https://code.visualstudio.com/docs/remote/ssh) if the integrated terminal is used, it is currently not possible for arbitrary terminal sessions.
10
10
11
-
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 it the file just fine.
11
+
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.
12
12
13
13
The aim of this project is to make the `code` cli available to _any_ terminal, not only to VS Code's integrated terminal.
14
14
15
15
## Prerequisites
16
16
17
-
-**Linux** - we make assumptions on where VS Code stores it data based on Linux
17
+
-**Linux** - we make assumptions on where VS Code stores its data based on Linux
18
18
19
19
> 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.
20
20
21
-
-**Python 3** - _tested under Python 3.8, but slightly older versions should work fine_
21
+
-**Python 3**
22
+
> Tested under Python 3.8, but slightly older versions should work fine
22
23
-**socat** - used for pinging UNIX sockets
23
24
```bash
24
25
apt-get install socat
25
26
```
26
27
27
-
### VS Code Server
28
+
### Visual Studio Code Server
29
+
30
+
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](https://code.visualstudio.com/docs/remote/ssh).
28
31
29
-
You need to set up VS Code Server before using this utility. For this, [connect to your target in a remote SSH session](https://code.visualstudio.com/docs/remote/ssh).
30
32
Afterwards, you should have a folder `.vscode-server` in your home directory.
31
33
32
34
## Installation
35
+
33
36
### [Fish](https://fishshell.com/)
37
+
38
+
#### Installing
39
+
34
40
With [fisher](https://github.com/jorgebucaran/fisher)
41
+
35
42
```fish
36
43
fisher install chvolkmann/code-connect
37
44
```
38
-
This downloads [`code_connect.py`](./functions/code_connect.py) and sets up an alias for you. See [`functions/code.fish`](./functions/code.fish)
45
+
46
+
This downloads [`code_connect.py`](./bin/code_connect.py) along with two functions. See [`functions/code.fish`](./functions/code.fish) and [`functions/code-connect.fish`](./functions/code-connect.fish)
47
+
48
+
You can autocomplete the repository name in subsequent commands, e.g. `fisher update code<TAB>`
This downloads [`code_connect.py`](./functions/code_connect.py) and sets up an alias for you. See [`install.sh`](./install.sh).
45
-
46
-
To uninstall, delete the alias from you `~/.bashrc` and remove `~/.code-connect`.
72
+
This downloads [`code_connect.py`](./bin/code_connect.py) along with two scripts and sets up aliases in your `.bashrc` for you. See [`bash/code.sh`](./bash/code.sh) and [`bash/code-connect.sh`](./bash/code-connect.sh)
47
73
48
-
###Manually
74
+
#### Uninstalling
49
75
50
-
Set up an alias for `code`, pointing to [`code_connect.py`](./functions/code_connect.py) by placing the following line in your shell's rcfile (bash: `~/.bashrc`, fish: `~/.config/fish/fuctions/code.fish`).
Deletes the aliases from `~/.bashrc` and removes the folder `~/.code-connect`
83
+
56
84
## Usage
57
-
Just use `code` like you normally would!
85
+
86
+
Use `code` as you would normally!
87
+
88
+
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 a IPC connected instance.
58
89
59
90
```
60
91
Usage: code [options][paths...]
@@ -81,17 +112,20 @@ See [CHANGELOG.md](./CHANGELOG.md)
81
112
82
113
## How it works
83
114
115
+
### VS Code Remote under the hood
116
+
84
117
VS Code uses datagram sockets to communicate between a terminal and the rendering window.
85
118
86
-
The integrated terminal as well as the WSL terminal spawn an IPC socket. You also create one when manually attaching a remote SSH session. These sockets can be found in the folder VS Code Server.
119
+
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.
87
120
88
-
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 binary can be found in `~/.vscode-server/bin/<commid-id>/bin/code`.
121
+
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/<commid-id>/bin/code`.
89
122
90
123
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](https://en.wikipedia.org/wiki/User_identifier) 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.
91
124
92
-
So the socket that is listening and that was accessed within a timeframe of 4 hours by default is chosen.
125
+
Thus the first socket that is listening and that was accessed within a timeframe of 4 hours by default is chosen.
126
+
127
+
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.
93
128
94
-
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.
95
129
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.
This returns `0` if and only if there's something listening.
112
146
147
+
### `code-connect` under the hood
148
+
113
149
The script `code_connect.py` performs all of the above steps and runs the VS Code `code` executable
114
-
as a child process with `VSCODE_IPC_HOOK_CLI` set properly.
150
+
as a child process with `VSCODE_IPC_HOOK_CLI` set properly, making it a drop-in replacement for `code`.
151
+
152
+
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:
153
+
154
+
-`code-connect`
155
+
Direct alias to `code_connect.py`
156
+
-`code`
157
+
Checks whether there is a `code` executable locally installed already and tries to use it if available. Otherwise, `code-connect` will be used.
115
158
116
-
## [Contributing](./CONTRIBUTING.md)
159
+
## Contributing
117
160
118
-
- Fork the repo
119
-
- Commit your changes to your branch
120
-
- Create a pull request
121
-
_Please make sure that [edits to your pull request are permitted](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)._
# Add the aliases to ~/.bashrc if not already done
109
+
ensure-alias "code""$CODE_SH"
110
+
ensure-alias "code-connect""$CODE_CONNECT_SH"
111
+
112
+
113
+
print ""
114
+
print "${c_emph}code-connect${c_fg} installed to ${c_path}$CODE_CONNECT_INSTALL_DIR${c_fg} successfully!"
115
+
print ""
116
+
print "Restart your shell or reload your ${c_path}.bashrc${c_fg} to see the changes."
117
+
print ""
118
+
print "${c_emph}source ${c_path}.bashrc"
119
+
print ""
120
+
121
+
122
+
local_code_binary=$(which code)
123
+
iftest -z "$local_code_binary";then
124
+
print "Local installation of ${c_emph}code${c_fg} detected at ${c_path}$local_code_binary"
125
+
print "Use the ${c_emph}code${c_fg} executable as you would normally."
126
+
print "If you want to connect to a remote VS Code session, use ${c_emph}code-connect${c_fg} as a drop-in replacement for ${c_emph}code${c_fg}!"
127
+
else
128
+
print "Use the ${c_emph}code${c_fg} executable as you would normally and you will interface with an open VS Code remote session, if available."
129
+
print "If you want to ${c_err}explicitly${c_fg} connect to a remote VS Code session, use ${c_emph}code-connect${c_fg} as a drop-in replacement for ${c_emph}code${c_fg}!"
0 commit comments