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
|
- `Cmd/Ctrl+Shift+O` to toggle the panel
|
||||||
- Server starts automatically when you open 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
|
## 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
|
## Windows Troubleshooting
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Command Mode Toggle
|
const customCmdSetting = new Setting(containerEl)
|
||||||
new Setting(containerEl)
|
|
||||||
.setName("Use custom command")
|
.setName("Use custom command")
|
||||||
.setDesc("Enable to use a custom shell command instead of the executable path")
|
.setDesc("Enable to use a custom shell command instead of the executable path")
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
@@ -78,14 +77,24 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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) {
|
if (this.settings.useCustomCommand) {
|
||||||
// Custom Command Mode
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Custom command")
|
.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) => {
|
.addTextArea((text) => {
|
||||||
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)
|
.setValue(this.settings.customCommand)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.settings.customCommand = value;
|
this.settings.customCommand = value;
|
||||||
@@ -96,10 +105,8 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
return text;
|
return text;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Path Mode
|
|
||||||
const pathSetting = new Setting(containerEl)
|
const pathSetting = new Setting(containerEl)
|
||||||
.setName("OpenCode path")
|
.setName("OpenCode executable path")
|
||||||
.setDesc("Path to the OpenCode executable. Leave empty to autodetect.")
|
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
.setPlaceholder("opencode")
|
.setPlaceholder("opencode")
|
||||||
@@ -110,7 +117,6 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add Autodetect button
|
|
||||||
pathSetting.addButton((button) => {
|
pathSetting.addButton((button) => {
|
||||||
button
|
button
|
||||||
.setButtonText("Autodetect")
|
.setButtonText("Autodetect")
|
||||||
@@ -132,7 +138,7 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Project directory")
|
.setName("Project directory")
|
||||||
.setDesc(
|
.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) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
@@ -293,7 +299,6 @@ export class OpenCodeSettingTab extends PluginSettingTab {
|
|||||||
cls: `opencode-status-badge ${statusClass[state]}`,
|
cls: `opencode-status-badge ${statusClass[state]}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show error message if state is error
|
|
||||||
if (state === "error") {
|
if (state === "error") {
|
||||||
const errorMsg = this.serverManager.getLastError();
|
const errorMsg = this.serverManager.getLastError();
|
||||||
if (errorMsg) {
|
if (errorMsg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user