Preface¶
When developing with DSH, after opening a code file in the sidebar (DSH-better-sidebar), you usually need to manually save the file and switch to the terminal to run it. This process adds extra steps. dsh-code-runner aims to address this pain point by automatically injecting a run button into the editor header, enabling one-click execution of code.
Feature Overview¶
- Automatic button injection: Automatically appends a run button to the end of the editor header.
- Smart filtering: Shows the button only for runnable code files, avoiding interference from files such as images or PDFs.
- Automatic saving: Automatically saves the current file before the button is clicked.
- Terminal management: Prioritizes running in the bottom terminal; automatically falls back to the right-side terminal on narrow screens or when the bottom panel is unavailable.
- Stable connection: Sends commands via WebSocket, maintains a stable connection, and prevents long-running tasks from being killed accidentally.
- Dependency handling: The installation script automatically detects and installs
dsh-better-sidebar, without requiring manual handling of base dependencies. - No pollution: Does not modify the DSH source code, does not register tools, and does not pollute the session context.
Installation and Enablement¶
Prerequisites¶
- DSH is installed and started.
- The environment requires Node.js >= 20.
- The target profile is initialized (default is
web).
Installation Steps¶
- Clone or obtain the source code.
- Run the installation script. Using the
webprofile as an example:
# macOS / Linux / Windows Git Bash
bash scripts/install.sh --profile web
# Windows PowerShell
powershell -ExecutionPolicy Bypass -File scripts/install.ps1 -Profile web
The script automatically detects dsh-better-sidebar. If it is not installed, the script will automatically execute the installation command.
- After installation is complete, restart DSH and hard-refresh the page (
Ctrl+Shift+R/Cmd+Shift+R).
Usage¶
- Open DSH-better-sidebar.
- Open a runnable code file in the file tree (supports multiple extensions such as
.py,.js,.ts,.go, and more). - Click the
▶button on the right side of the editor header. - The plugin automatically saves the file, opens or focuses the bottom terminal, and executes the current file.
Technical Details and Supported Scope¶
- Implementation principle: Uses
MutationObserverto monitor changes in the editor header and reuses the/sidebar/ws/terminalWebSocket protocol of better-sidebar to send commands. - Supported languages: Supports JavaScript/TypeScript, Python, Ruby, PHP, Perl, C/C++, Java, Kotlin, Swift, Go, Rust, Zig, Shell, PowerShell, Lua, R, Julia, Dart, Elixir, Scala, F#, Haskell, OCaml, Clojure, Groovy, Nim, V, and more.
Notes¶
- This plugin depends on
dsh-better-sidebar, which is handled automatically during installation. - Ensure that the Node.js version in your environment meets the requirement (>= 20).
- The plugin follows the MIT license.