Scarab Plugin Examples - Index

This directory contains comprehensive examples for developing Scarab plugins using Fusabi.

Documentation

FileDescription
QUICKSTART.mdGet started in 5 minutes - basic patterns and templates
README.mdComplete API reference and plugin development guide
INDEX.mdThis file - overview of all examples

Configuration Examples

FileDescription
plugins.tomlComplete plugin configuration example with all options

Example Plugins

Beginner Examples

PluginLOCDescriptionKey Concepts
hello-plugin.fsx~60Simplest possible pluginPlugin structure, metadata, on_load hook, logging

Intermediate Examples

PluginLOCDescriptionKey Concepts
output-filter.fsx~120Highlight errors in outputon_output hook, regex patterns, overlays, configuration
custom-keybind.fsx~200Custom keyboard shortcutson_input hook, key detection, modals, command palette
git-status.fsx~180Display git status indicatoron_pre/post_command, external processes, persistent overlays
notification-monitor.fsx~150Notify on long-running commandsStateful tracking, time measurement, notifications

Advanced Examples

PluginLOCDescriptionKey Concepts
session-manager.fsx~260Advanced session managementClient attach/detach, persistent state, complex UI, file I/O
scarab-atuin.fsx~450Atuin shell history integrationExternal tool integration, JSON parsing, modal search UI, real-time filtering

Plugin Complexity Matrix

Simple Output   │ hello-plugin.fsx
      ↓         │
Pattern Match   │ output-filter.fsx
      ↓         │
Input Handling  │ custom-keybind.fsx
      ↓         │
External Procs  │ git-status.fsx
      ↓         │
State + Time    │ notification-monitor.fsx
      ↓         │
Full Featured   │ session-manager.fsx, scarab-atuin.fsx

Hooks Demonstrated

HookUsed In
on_loadAll plugins
on_unloadAll plugins (cleanup)
on_outputoutput-filter.fsx
on_inputcustom-keybind.fsx, session-manager.fsx, scarab-atuin.fsx
on_pre_commandgit-status.fsx, notification-monitor.fsx
on_post_commandgit-status.fsx, notification-monitor.fsx, scarab-atuin.fsx
on_resizegit-status.fsx, session-manager.fsx
on_attachsession-manager.fsx
on_detachsession-manager.fsx
on_remote_commandcustom-keybind.fsx, git-status.fsx, notification-monitor.fsx, session-manager.fsx, scarab-atuin.fsx

Features Demonstrated

Core Features

  • Plugin metadata and registration (all plugins)
  • Logging at different levels (all plugins)
  • Context API usage (all plugins)

Terminal Interaction

  • Reading terminal size (hello-plugin.fsx)
  • Reading cursor position (output-filter.fsx)
  • Reading terminal lines (git-status.fsx)
  • Reading/writing cells (potential addition)

Input/Output Handling

  • Output interception (output-filter.fsx)
  • Input interception (custom-keybind.fsx, scarab-atuin.fsx)
  • Input modification (custom-keybind.fsx, scarab-atuin.fsx)
  • Regex pattern matching (output-filter.fsx)

UI Components

  • Drawing overlays (all visual plugins)
  • Clearing overlays (all visual plugins)
  • Showing modals (custom-keybind.fsx, session-manager.fsx, scarab-atuin.fsx)
  • Command palette integration (most plugins)
  • User notifications (notification-monitor.fsx, scarab-atuin.fsx)

State Management

  • Simple mutable state (output-filter.fsx, scarab-atuin.fsx)
  • Dictionary tracking (notification-monitor.fsx)
  • Persistent state (session-manager.fsx)
  • Configuration reading (all plugins)

External Integration

  • Running shell commands (git-status.fsx, scarab-atuin.fsx)
  • Environment variable access (hello-plugin.fsx)
  • File I/O (session-manager.fsx)
  • Time tracking (notification-monitor.fsx)
  • JSON parsing (scarab-atuin.fsx)
  • External tool integration (scarab-atuin.fsx)

Advanced Patterns

  • Command duration tracking (notification-monitor.fsx)
  • Client lifecycle management (session-manager.fsx)
  • Color coding and themes (session-manager.fsx)
  • Error handling (all plugins)
  • Real-time search filtering (scarab-atuin.fsx)
  • Graceful degradation (scarab-atuin.fsx)

Learning Path

Level 1: Getting Started

  1. Read QUICKSTART.md
  2. Copy and modify hello-plugin.fsx
  3. Experiment with logging and terminal state

Level 2: Basic Functionality

  1. Study output-filter.fsx for output hooks
  2. Study custom-keybind.fsx for input hooks
  3. Build a simple plugin combining both

Level 3: Integration

  1. Study git-status.fsx for external processes
  2. Study notification-monitor.fsx for state tracking
  3. Build a plugin that monitors something in your environment

Level 4: Advanced Features

  1. Study session-manager.fsx for complex state
  2. Study scarab-atuin.fsx for external tool integration
  3. Implement persistent storage
  4. Build a full-featured plugin for your workflow

Real-World Plugin Examples

scarab-atuin.fsx - Shell History Integration

This production-quality plugin demonstrates:

  • Tool detection: Check if external tools are installed
  • JSON parsing: Parse structured output from external commands
  • Modal search UI: Interactive search with real-time filtering
  • Keyboard navigation: Arrow keys, Enter, Escape handling
  • Command insertion: Insert selected text into terminal
  • Error handling: Graceful degradation when tool unavailable
  • Configuration: Multiple config options
  • Command palette: Integration with Scarab’s command system

Key features:

  • Integrates Atuin shell history tool
  • Ctrl+R opens search modal
  • Real-time search filtering
  • Arrow key navigation
  • Enter to select and insert command
  • Auto-sync support (optional)
  • Statistics display

Perfect for learning:

  • How to integrate external CLI tools
  • Building interactive search interfaces
  • Parsing and displaying external data
  • User-friendly error messages
  • Production plugin patterns

Plugin Ideas to Try

Easy

  • clock-plugin.fsx - Display current time in corner
  • prompt-customizer.fsx - Add custom prompt indicators
  • directory-tracker.fsx - Show current directory
  • battery-indicator.fsx - Show laptop battery status

Medium

  • tmux-integration.fsx - Integrate with tmux sessions
  • ssh-helper.fsx - Detect SSH connections and show hostname
  • clipboard-manager.fsx - Advanced clipboard history
  • auto-suggestions.fsx - Command completion suggestions
  • atuin-integration.fsx - Integrate Atuin shell history (scarab-atuin.fsx)

Advanced

  • multiplexer.fsx - Full terminal multiplexer
  • recording-plugin.fsx - Record and replay terminal sessions
  • collaboration.fsx - Share terminal with others
  • ai-assistant.fsx - Integrate with AI for command help
  • fzf-integration.fsx - Integrate fzf fuzzy finder
  • zoxide-integration.fsx - Smart directory jumping

Testing Checklist

When developing plugins, test:

  • Plugin loads without errors
  • Hooks execute at expected times
  • Overlays appear in correct positions
  • Terminal resize doesn’t break UI
  • Configuration is read correctly
  • Cleanup happens on unload
  • No memory leaks with long-running sessions
  • Error messages are helpful
  • External tool failures handled gracefully
  • Search and filtering work smoothly

Contributing

To contribute new examples:

  1. Follow the existing file naming convention
  2. Include comprehensive metadata comments
  3. Add inline comments explaining non-obvious logic
  4. Update this INDEX.md with your example
  5. Update README.md if you introduce new patterns
  6. Submit a PR with description of what your example teaches

Resources

License

All examples are MIT/Apache-2.0 licensed (same as Scarab).