Example Plugin
This is a complete example plugin that demonstrates all major plugin features. The "Electrobun Demo Plugin" is included in the Colab repository at test-plugin/ as a comprehensive reference implementation.
package.json
{
"name": "colab-electrobun-demo",
"version": "1.0.0",
"description": "Comprehensive demo of the Colab plugin API - powered by Electrobun!",
"main": "index.ts",
"keywords": ["colab-plugin"],
"author": "Colab Team",
"license": "MIT",
"colab-plugin": {
"displayName": "Electrobun Demo Plugin",
"description": "A comprehensive demo of the Colab plugin API with bunnies and lightning bolts",
"main": "index.ts",
"contributes": {
"commands": [
{ "id": "electrobun.zap", "title": "Zap! Enable Electrobun Mode" },
{ "id": "electrobun.rest", "title": "Rest - Disable Electrobun Mode" },
{ "id": "electrobun.showGitStatus", "title": "Show Git Status" },
{ "id": "electrobun.findFiles", "title": "Find TypeScript Files" },
{ "id": "electrobun.runShell", "title": "Run Shell Command Demo" },
{ "id": "electrobun.openDocs", "title": "Open Electrobun Docs" }
],
"webviewHooks": ["onLoad"]
},
"entitlements": {
"filesystem": { "read": true, "write": true },
"network": { "internet": true, "domains": ["electrobun.dev"] },
"process": { "spawn": true },
"webview": { "scriptInjection": true },
"terminal": { "commands": true },
"ui": { "statusBar": true, "contextMenu": true, "fileDecorations": true, "notifications": true },
"editor": { "completions": true },
"keybindings": { "global": true }
},
"activationEvents": ["*"]
}
} index.ts
The full implementation is in the test-plugin/index.ts file in the Colab repository. Here's the basic structure:
import type { PluginAPI, Disposable } from 'colab/src/main/plugins/types';
const disposables: Disposable[] = [];
export async function activate(api: PluginAPI): Promise<void> {
// Register features and push disposables to the array
disposables.push(api.commands.registerCommand('myPlugin.command', handler));
disposables.push(api.terminal.registerCommand('mycmd', terminalHandler));
// ... see test-plugin/index.ts for complete examples
}
export async function deactivate(): Promise<void> {
disposables.forEach(d => d.dispose());
disposables.length = 0;
} See the API Reference for documentation on each API, and browse the full test-plugin/ source code for working examples of every feature.
Features Demonstrated
- Webview Preload Scripts - Injects JavaScript that adds an Electrobun badge to web pages
- Commands -
electrobun.zap,electrobun.rest,electrobun.showGitStatus, and more - Terminal Commands - Type
zap,bunny, orpathsin any terminal - Code Completions - Type
console.in JS/TS files for electrobun-themed snippets - Status Bar Item - Shows "Electrobun" status with periodic updates
- File Decorations - TypeScript files show ⚡, JavaScript files show 🐰, .bunny files show ⚡🐰
- Context Menu - Right-click to "Electrify this file" or "Create .bunny file"
- Keyboard Shortcuts -
Cmd+Shift+Ztriggers the zap command - Settings Panel - Configure auto-zap, default zap count, status bar color, and more
- Custom Slates - Open any
.bunnyfile to see a custom viewer with embedded terminal - Persistent State - Tracks activation count and last load time across sessions
- Git Integration - Shows current branch via the "Show Git Status" command
- Event Subscriptions - Logs file changes and active editor switches
Running the Example
The test plugin is located in the Colab repository at test-plugin/. To install it:
- Open Colab
- Click "Plugins" in the status bar
- Click "Install from folder"
- Navigate to and select the
test-pluginfolder - The plugin will be installed and activated automatically
Testing the Features
- Webview: Open a web browser tab - an ⚡🐰 badge appears in the corner
- Terminal: Type
zap,bunny, orpaths - Editor: Create a
.tsfile and typeconsole. - Status Bar: Look for "⚡🐰 Electrobun" on the right side
- File Tree: TypeScript files show ⚡, JavaScript files show 🐰
- Context Menu: Right-click a file for "Electrify" or "Create .bunny file"
- Keyboard: Press
Cmd+Shift+Zanywhere to zap - Settings: Click on the status bar item to open settings
- Custom Slate: Create a
.bunnyfile and open it to see the custom viewer