nushell-plugins/guides/register-core-plugins.md

1 line
11 KiB
Markdown
Raw Normal View History

# Registering Nushell Core Plugins\n\n**Version**: 1.0.0\n**Updated**: 2025-10-22\n**Nushell**: 0.108.0+\n\n## Overview\n\nNushell core plugins are built-in plugins that come with Nushell when you build it with the `--workspace` flag. They provide essential functionality like data analysis, format conversion, Git integration, and more.\n\n**Core plugins include**:\n\n- `nu_plugin_polars` - Data analysis with Polars\n- `nu_plugin_formats` - Format conversion\n- `nu_plugin_inc` - Increment operations\n- `nu_plugin_gstat` - Git status information\n- `nu_plugin_query` - Advanced querying\n- `nu_plugin_custom_values` - Custom value handling\n- `nu_plugin_example` - Example plugin template\n- `nu_plugin_stress_internals` - Stress testing\n\n---\n\n## How Plugin Registration Works\n\nWhen you register a plugin, you're telling Nushell where to find the plugin binary and to load it automatically. This happens by:\n\n1. **Registering**: `nu -c "plugin add /path/to/nu_plugin_*"`\n - Adds plugin path to Nushell config\n - Plugin loads on next Nushell startup\n\n2. **Listing**: `nu -c "plugin list"`\n - Shows all registered plugins\n - Verifies registration worked\n\n3. **Removing**: `nu -c "plugin rm plugin_name"`\n - Removes plugin from config\n - Plugin unloads after restart\n\n---\n\n## Method 1: Manual Registration\n\n### Register a Single Core Plugin\n\n```bash\n# After building nushell with --workspace\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_polars"\n```\n\nReplace the path with your actual Nushell target directory.\n\n### Register Multiple Core Plugins\n\n```bash\n# Register all built plugins\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_polars"\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_formats"\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_inc"\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_gstat"\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_query"\nnu -c "plugin add /path/to/nushell/target/release/nu_plugin_custom_values"\n```\n\n### Verify Registration\n\n```bash\nnu -c "plugin list"\n```\n\nExpected output shows all registered plugins with their versions.\n\n---\n\n## Method 2: Script-Based Registration\n\n### Using the Installation Script\n\nIf plugins are in `~/.local/bin/`:\n\n```bash\n./install_from_manifest.nu --all --register-only\n```\n\nThis registers all plugins from the manifest.\n\n### Using a Custom Nushell Script\n\nCreate a file `register_core_plugins.nu`:\n\n```nushell\n#!/usr/bin/env nu\n\n# Register Nushell core plugins\ndef register_core_plugins [plugin_dir: string] {\n let core_plugins = [\n "nu_plugin_polars"\n "nu_plugin_formats"\n "nu_plugin_inc"\n "nu_plugin_gstat"\n "nu_plugin_query"\n "nu_plugin_custom_values"\n ]\n\n for plugin in $core_plugins {\n let plugin_path = $"($plugin_dir)/($plugin)"\n\n if ($plugin_path | path exists) {\n try {\n # Remove old registration if exists\n nu -c $"plugin rm ($plugin | str replace '^nu_plugin_' '')" out+err>| null\n } catch {}\n\n # Register new\n nu -c $"plugin add ($plugin_path)"\n print $"✓ Registered: ($plugin)"\n } else {\n print $"✗ Not found: ($plugin_path)"\n }\n }\n}\n\n# Main\nlet plugin_dir = if ($env | get -i NUSHELL_PLUGIN_DIR) != null {\n $env.NUSHELL_PLUGIN_DIR\n} else {\n "/path/to/nushell/target/release"\n}\n\nregister_core_plugins $plugin_dir\n```\n\nRun it:\n\n```bash\nchmod +x register_core_plugins.nu\n./register_core_plugins.nu\n```\n\n---\n\n## Method 3: After Building Nushell\n\n### Step-by-Step After `cargo build --workspace`\n\n**1. Build Nushell with workspace (includes core plugins)**:\n\n```bash\ncd nushell\ncargo build --release --workspace\n```\n\n**2. Find where core plugins were built**:\n\n```bash\nls nushell/target/release/nu_plugin_*\n```\n\n**3. Copy to installation directory** (optional, for easy access):\n\n```bash\ncp nushell/