Fusabi Plugin Examples
This directory contains example Fusabi plugins for the Scarab terminal emulator.
Plugin Structure
Fusabi plugins are written in F# syntax (.fsx files) and compiled to bytecode (.fzb files) for execution.
Directory Layout
examples/fusabi/
├── README.md # This file
├── TEMPLATE.fsx # Plugin template for creating new plugins
├── hello.fsx # Simple hello world example
├── theme.fsx # Theme customization example
├── keybindings.fsx # Custom keybindings example
└── ui_overlay.fsx # UI overlay example
Plugin Metadata
All plugins must include metadata comments at the top of the file:
// @name plugin-name
// @version 1.0.0
// @description Short description of what the plugin does
// @author Your Name
// @homepage https://github.com/yourusername/plugin-name (optional)
// @license MIT (optional)
// @api-version 0.1.0
// @min-scarab-version 0.1.0Plugin Lifecycle Hooks
Plugins can implement the following lifecycle hooks:
on_load- Called when plugin is loadedon_unload- Called when plugin is unloaded
Event Hooks
Plugins can hook into terminal events:
on_output- Intercept terminal output before displayon_input- Intercept user input before sending to PTYon_pre_command- Called before command executionon_post_command- Called after command completeson_resize- Called when terminal is resizedon_attach- Called when client attacheson_detach- Called when client detacheson_remote_command- Handle remote commands from client
Building Plugins
Build Single Plugin
just plugin-build examples/fusabi/hello.fsxBuild All Plugins
just plugin-build-allWatch for Changes
just plugin-watchValidating Plugins
Validate Single Plugin
just plugin-validate examples/fusabi/hello.fsxValidate All Plugins
just plugin-validate-allCreating New Plugins
From Template
just plugin-new my-pluginThis creates examples/fusabi/my-plugin.fsx from the template.
Manual Creation
- Copy
TEMPLATE.fsxto a new file - Update the metadata at the top
- Implement your plugin logic
- Build and validate:
just plugin-build examples/fusabi/my-plugin.fsx
just plugin-validate examples/fusabi/my-plugin.fsxPlugin Development Workflow
- Create - Create new plugin from template
- Develop - Write plugin logic with hot-reload support
- Build - Compile .fsx to .fzb bytecode
- Validate - Check metadata and structure
- Test - Load in Scarab daemon and test functionality
- Deploy - Install to
~/.config/scarab/plugins/
Plugin API
Context Object
The PluginContext provides access to Scarab internals:
type PluginContext = {
// Send notification to client
notify: string -> unit
// Log message
log: LogLevel -> string -> unit
// Register command
register_command: string -> (unit -> unit) -> unit
// Get terminal size
get_terminal_size: unit -> (uint16 * uint16)
// Send data to PTY
write_to_pty: byte[] -> unit
}Action Types
Hooks return actions to control data flow:
type Action =
| Continue // Pass through unchanged
| Block // Suppress (don't process)
| Modified of 'T // Pass modified versionTesting Plugins
Unit Tests
cargo test -p scarab-daemon pluginIntegration Tests
# Start daemon with plugin
cargo run -p scarab-daemon -- --plugin examples/fusabi/hello.fzb
# In another terminal, start client
cargo run -p scarab-clientExamples Explained
hello.fsx
Simple example demonstrating:
- Basic metadata
- Plugin initialization
- Console output
theme.fsx
Demonstrates:
- Color scheme customization
- UI configuration
- Theme switching
keybindings.fsx
Demonstrates:
- Input interception
- Custom key combinations
- Command binding
ui_overlay.fsx
Demonstrates:
- Custom UI rendering
- Remote commands
- Client-side integration
Best Practices
- Metadata - Always include complete metadata
- Error Handling - Return
Resulttypes, handle errors gracefully - Performance - Keep hooks fast, avoid blocking operations
- State - Use mutable state sparingly, prefer functional style
- Testing - Validate plugins before deploying
- Documentation - Comment your code, especially public functions
Plugin Installation
Development
Plugins in examples/fusabi/ are automatically discovered during development.
Production
Install plugins to:
~/.config/scarab/plugins/
Or system-wide:
/usr/share/scarab/plugins/
Troubleshooting
Plugin Not Loading
- Check metadata is complete and valid
- Validate plugin:
just plugin-validate your-plugin.fsx - Check Scarab logs for errors
- Verify API version compatibility
Compilation Errors
- Check F# syntax
- Ensure all types match API definitions
- Run with verbose flag:
./scripts/build-plugin.sh -v your-plugin.fsx
Runtime Errors
- Enable debug mode in plugin
- Check daemon logs
- Test plugin in isolation
Resources
Contributing
To contribute example plugins:
- Create plugin in
examples/fusabi/ - Add metadata and documentation
- Validate:
just plugin-validate-all - Submit pull request
License
Example plugins are provided as-is under the MIT license.