Introduction
dc2host python package is intended to be used for interaction between VS Code running Dev Containers and other development tools that run on the host system (e.g. git difftool etc).
It also contains a command line interface that can be used without VS Code just to open a source file from a local Git repository in GitLab/GitHub Web UI with the specified line number selected.
git difftool example
Suppose you have your favorite GUI git difftool configured to run from VS Code for the current file. This setup won't work when you start using Dev Containers because your host system is isolated from VS Code Server and file paths are different for what VS Code sees in a container and for what git difftool sees on the host.
To resolve this problem dc2host runs a simple REST server on the host that handles requests from Dev Containers and knows how to translate file paths to use them on the host.
Supported REST endpoints
run command
POST /run
{
"cwd": <container directory where from to execute the specified command>,
"args": ["command", "argument1", "argument2"],
"check": false|true - check for zero exit code
}
Example:
curl -d "{\"args\": [\"git\", \"difftool\", \"file/relative/path\"], \"cwd\": \"/workspace/directory\"}" -H "Content-Type: application/json" host.docker.internal:5000/run
open_in_browser command
Opens the specified file from a local repo in Web browser on GitHub/GitLab.
POST /open_in_browser
{
"file": <file path in a container directory>,
"lineNumber": <line number to highlight (optional)>
}
Example:
curl -d "{\"file\": \"file1.txt\", \"lineNumber\": 42}" -H "Content-Type: application/json" host.docker.internal:5000/run
Quick start
Open file "README.md" from a local directory on GitHub:
python -m dc2host open README.md
Run Flask on Windows host:
python -m flask --app dc2host.app run --debug --host=0.0.0.0
Configure VS Code "tasks.json"
{
"tasks": [
{
"label": "Open in GitHub/GitLab",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"file\": \"${file}\", \"lineNumber\": ${lineNumber}}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/open_in_browser"
],
},
{
"label": "Diff current file",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"args\": [\"git\", \"difftool\", \"${fileBasename}\"], \"cwd\": \"${fileDirname}\"}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/run"
],
},
{
"label": "History current file",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"args\": [\"gitk\", \"--\", \"${fileBasename}\"], \"cwd\": \"${fileDirname}\", \"check\": false}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/run"
],
}
]
}
Configure VS Code "keybindings.json"
[
{
"key": "ctrl+k ctrl+d",
"command": "workbench.action.tasks.runTask",
"args": "Diff current file"
}
]
Metadata
Release files for dc2host 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dc2host-1.0.0.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dc2host-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.4 kB
Release files / dc2host-1.0.0.tar.gz
| Download URL | dc2host-1.0.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a75b482fe2305d95c587b7e92bdaaa5818be7125b35bd0fa7b1abc88b9e326c1
|
|
BLAKE2b-256 checksum How to use checksums |
e884416ce4ea10527a20698b15dd4a4d9cee2503bc6ccba82612b3686df25671
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / dc2host-1.0.0-py3-none-any.whl
| Download URL | dc2host-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9eb242de775378a21ea3b9f26ea072c691c489f7b46fc2b922653e0c0bd7c10
|
|
BLAKE2b-256 checksum How to use checksums |
5e42866f35f29cd277fe2916b5294b34e915fa221034e53b90470d1f8fba0216
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|