From 2c17c9e7f6583971bbd7d5b8fcc3a0503697aa1f Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Sun, 15 Feb 2026 08:47:34 +0100 Subject: [PATCH] Update readme, document 'custom command' --- README.md | 30 +++++++++++++++++++++--------- src/settings/SettingsTab.ts | 27 ++++++++++++++++----------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6f20421..7b0c8a8 100644 --- a/README.md +++ b/README.md @@ -56,18 +56,30 @@ If you want to contribute or develop the plugin: - `Cmd/Ctrl+Shift+O` to toggle the panel - Server starts automatically when you open the panel -## Context injection (experimental) - -This plugin can automatically inject context to the running OC instance: list of open notes and currently selected text. - -It can be configured form the plugin settings. - -Currently, this is work-in-progress feature with some limitations: -- It won't work when creating new session from OC interface. ## Settings -Available plugin settings +### Custom Command Mode + +Enable "Use custom command" when you need more control over how OpenCode starts—for example, to add extra CLI flags, use a custom wrapper script, or run OpenCode through a container or virtual environment. + +When using custom command: + +- **Hostname and port must match** the values set in the Port and Hostname fields above +- You **must include `--cors app://obsidian.md`** to allow Obsidian to embed the OpenCode interface + +Example: +```bash +opencode serve --port 14096 --hostname 127.0.0.1 --cors app://obsidian.md +``` + +Other settings (port, hostname, auto-start, view location, context injection) are available through the settings UI and are self-explanatory. + +### Context injection (experimental) + +This plugin can automatically inject context to the running OC instance: list of open notes and currently selected text. + +Currently, this is work-in-progress feature with some limitations - it won't work when creating new session from OC interface. ## Windows Troubleshooting diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index 02ca474..a50ed5c 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -63,8 +63,7 @@ export class OpenCodeSettingTab extends PluginSettingTab { }) ); - // Command Mode Toggle - new Setting(containerEl) + const customCmdSetting = new Setting(containerEl) .setName("Use custom command") .setDesc("Enable to use a custom shell command instead of the executable path") .addToggle((toggle) => @@ -77,15 +76,25 @@ export class OpenCodeSettingTab extends PluginSettingTab { this.display(); }) ); + + const descEl = customCmdSetting.descEl; + descEl.createEl("br"); + const linkEl = descEl.createEl("a", { + text: "Learn more", + href: "https://github.com/mtymek/opencode-obsidian#custom-command-mode" + }); + linkEl.addEventListener("click", (e) => { + e.preventDefault(); + window.open(linkEl.href, "_blank"); + }); if (this.settings.useCustomCommand) { - // Custom Command Mode new Setting(containerEl) .setName("Custom command") - .setDesc("Full shell command to start OpenCode. You control all arguments (e.g., 'opencode serve --port 14096')") + .setDesc("Custom shell command to start OpenCode.") .addTextArea((text) => { text - .setPlaceholder("opencode serve --port 14096 --hostname 127.0.0.1") + .setPlaceholder("opencode serve --port 14096 --hostname 127.0.0.1 --cors app://obsidian.md") .setValue(this.settings.customCommand) .onChange(async (value) => { this.settings.customCommand = value; @@ -96,10 +105,8 @@ export class OpenCodeSettingTab extends PluginSettingTab { return text; }); } else { - // Path Mode const pathSetting = new Setting(containerEl) - .setName("OpenCode path") - .setDesc("Path to the OpenCode executable. Leave empty to autodetect.") + .setName("OpenCode executable path") .addText((text) => text .setPlaceholder("opencode") @@ -110,7 +117,6 @@ export class OpenCodeSettingTab extends PluginSettingTab { }) ); - // Add Autodetect button pathSetting.addButton((button) => { button .setButtonText("Autodetect") @@ -132,7 +138,7 @@ export class OpenCodeSettingTab extends PluginSettingTab { new Setting(containerEl) .setName("Project directory") .setDesc( - "Override the starting directory for OpenCode. Leave empty to use the vault root. Supports ~ for home directory." + "Override the starting directory for OpenCode. Leave empty to use the vault root." ) .addText((text) => text @@ -293,7 +299,6 @@ export class OpenCodeSettingTab extends PluginSettingTab { cls: `opencode-status-badge ${statusClass[state]}`, }); - // Show error message if state is error if (state === "error") { const errorMsg = this.serverManager.getLastError(); if (errorMsg) {