Plugins

Nu can be extended using plugins. Plugins behave much like Nu’s built-in commands, with the added benefit that they can be added separately from Nu itself.

Nu plugins are executables; Nu launches them as needed and communicates with them over stdin, stdout, and stderrPlugins - 图1 (opens new window). Nu plugins can use either JSON or Cap’n ProtoPlugins - 图2 (opens new window) as their communication encoding.

Adding a plugin

To add a plugin, call the register command to tell Nu where to find it. As you do, you’ll need to also tell Nushell what encoding the plugin uses.

Linux+macOS:

  1. > register --encoding=capnp ./my_plugins/my-cool-plugin

Windows:

  1. > register --encoding=capnp .\my_plugins\my-cool-plugin.exe

When register is called:

  1. Nu launches the plugin and sends it a “Signature” message over stdin
  2. The plugin responds via stdout with a message containing its signature (name, description, arguments, flags, and more)
  3. Nu saves the plugin signature in the file at $nu.plugin-path, so registration is persisted across multiple launches

Once registered, the plugin is available as part of your set of commands:

  1. > help commands | where is_plugin == true

Examples

Nu’s main repo contains example plugins that are useful for learning how the plugin protocol works:

Debugging

The simplest way to debug a plugin is to print to stderr; plugins’ standard error streams are redirected through Nu and displayed to the user.

Help

Nu’s plugin documentation is a work in progress. If you’re unsure about something, the #plugins channel on the Nu DiscordPlugins - 图5 (opens new window) is a great place to ask questions!