Update readme, document 'custom command'
This commit is contained in:
30
README.md
30
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
|
||||
|
||||
<img src="./assets/plugin_settings.png" alt="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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user