@ppsteven/vsopen
v1.0.0
Published
Generate and open VS Code remote SSH URLs for local files
Downloads
9
Maintainers
Readme
vsopen
Generate and open VS Code remote SSH URLs for local files.
Installation
Install globally via npm:
npm install -g vsopenOr use directly with npx (no installation required):
npx vsopen <file>Usage
vsopen <file>
vsopen --alias <alias> <file>
vsopen -a <alias> <file>Environment Variable
You can also set a default alias via environment variable:
export VSOPEN_ALIAS=mini
vsopen <file>Options
-a, --alias <alias>- Override username@ip with custom alias-h, --help- Display help message-V, --version- Display version
Examples
Basic Usage
$ vsopen ./test.js
点击下方链接跳转打开本地 VS Code:
vscode://vscode-remote/[email protected]/Users/ppsteven/projects/test.js:1Opens VS Code automatically at line 1.
With Alias Flag
$ vsopen --alias mini ./test.js
点击下方链接跳转打开本地 VS Code:
vscode://vscode-remote/ssh-remote+mini/Users/ppsteven/projects/test.js:1With Environment Variable
$ export VSOPEN_ALIAS=mini
$ vsopen ./test.js
点击下方链接跳转打开本地 VS Code:
vscode://vscode-remote/ssh-remote+mini/Users/ppsteven/projects/test.js:1Absolute Paths
Both relative and absolute paths work:
$ vsopen /absolute/path/to/file.txt
$ vsopen ./relative/path/file.txt
$ vsopen ../parent/file.txtAll paths are automatically resolved to absolute paths.
Platform Support
- macOS: Full support with automatic IP detection (en0 → en1 → hostname)
- Linux: Full support with automatic IP detection via
hostname -I - Windows: Basic support (uses hostname instead of IP)
How It Works
- Resolves the file path to an absolute path
- Detects your username and IP address (or uses provided alias)
- Determines if the path is a file or directory
- Generates a VS Code remote SSH URL:
vscode://vscode-remote/ssh-remote+{host}{path} - For files, appends
:1to open at the first line - Prints the URL to stdout
- Automatically opens the URL in VS Code
Requirements
- Node.js >= 14
- VS Code installed with Remote-SSH extension
Error Handling
- File not found: Shows clear error message with the path
- Missing file argument: Displays help message
- Failed to open VS Code: Prints URL for manual copying
- IP detection failure: Gracefully falls back to hostname
License
MIT
Author
Created as a Node.js port of the shell vlink function.
