Nushell Documentation

repository·main·Indexed 42 days ago

https://github.com/nushell/nushell.github.io

A modern, cross-platform shell that treats everything as structured data. Nushell replaces traditional string-based pipelines with typed data pipelines for safer and more intuitive data manipulation, including native support for JSON, YAML, SQLite, and Excel.

Tokens
235.4K
Snippets
1.2K
Records
1.6K
Agent score
53%

What's inside Nushell

  1. Overview of Nushell

    main

    Nushell is a modern, cross-platform shell that combines the Unix philosophy of piping simple commands together with the features of a rich programming language. Unlike traditional shells, Nushell works directly with structured data rather than just raw text strings.

    Key focus areas include:

    • Flexible cross-platform shell: A modern feel across different operating systems.
    • Structured data processing: Solving problems using a programming language designed to work with the structure of your data.
    • Developer experience: Providing clear error messages and clean IDE support.
  2. Overview of Nushell features

    main

    Nushell is a new type of shell designed around structured data and type safety.

    • Everything is data: Nu pipelines use structured data, allowing you to safely select, filter, and sort data without manual string parsing.
    • Native Data Support: Nu supports formats like JSON, YAML, SQLite, and Excel out of the box.
    • Type Safety: Nu operates on typed data, which helps catch bugs and provides detailed error messages indicating exactly where and why a failure occurred.
    • Extensibility: Nu features a powerful plugin system for easy extension.
  3. Nushell 0.98.0 Release Highlights

    main

    Nushell 0.98.0 introduced several significant changes to error handling, evaluation, and parsing:

    • Error Handling: Non-zero exit codes are now treated as errors. Core dump errors are always printed, and SIGPIPE no longer triggers an error. Other signal termination message printing is controlled by a specific setting.
    • Evaluator: The Intermediate Representation (IR) evaluator is now the default.
    • Clipboard: Support for the system clipboard has been removed.
    • Record Parsing: Changes were made to how records are parsed, specifically relaxing the requirement for parentheses in certain contexts.
    • Plugins: Switched from bincode to MessagePack for plugin custom values.
  4. Performance improvements in Nushell 0.115.0

    main

    Nushell 0.115.0 introduced significant performance optimizations for handling large data structures and specific string operations:

    • Large Binary Values: Cloning, streaming, slicing, and converting large binary values is substantially cheaper. Repeated slicing and integer conversion is approximately 3.4x faster due to reduced copying.
    • Large Lists and Tables: Accessing elements (e.g., $list.0) or loading large lists into variables and closures is much faster. Accessing small parts of large lists no longer requires copying the entire list.
    • String Replacement: str replace --regex and str replace --multiline are roughly 10x faster when processing lists, tables, or records containing many string values.
    • Lazy lines Command: When using lines with a string value (non-stream) input, it now returns a list stream and produces items lazily instead of eagerly creating a full list.
    • Regex Caching: Built-in commands using the --regex parameter now utilize an LRU cache, improving performance in tight loops.
  5. New features in Nushell 0.84.0

    main

    Nushell 0.84.0 introduced several key improvements:

    • Constants from modules: You can now access constants defined within modules.
    • Compact table display: New options are available for more compact table rendering.
    • Consistent format ... commands: Improvements to the consistency of formatting commands.
    • scope command enhancements: Updates to how scope is handled and inspected.
    • Improved http commands: Better handling of HTTP headers.
    • Dataframe features: Ongoing work on optional dataframe capabilities.
    • Command organization: Refined organization of commands within the shell.
  6. New features in Nushell 0.80

    main

    Key features and improvements in version 0.80 include:

    • Modules from directories: Use directories as modules by including a mod.nu file.
    • Record type annotations: Define types for records.
    • Standard Library Updates:
      • Added bench command.
      • Added main command to toolkit.nu.
      • Added --expand option to std clip.
      • Improved std help with filtering by name, usage, and search terms.
      • Added log custom command and exported log levels.
      • Added input list subcommand for interactive selections.
    • Glob Improvements:
      • Added a negation glob option to the glob command.
      • Added support for listening to signals on the glob command.
    • Other Improvements:
      • Added --redirect-combine option to run-external.
      • Added --ide-ast for a simplified AST for editor integration.
      • Added extern def which allows raw arguments.
  7. Manage NuShell plugins with the `plugin` command

    main

    The plugin command is a built-in command used to manage the lifecycle of NuShell plugins, including adding them to the registry, loading them into the current scope, and listing or removing them.

    Note that plugin use is a keyword used to load a plugin from the registry into your current session, whereas other subcommands manage the registry or the running state of the plugin.

    # Example workflow
    plugin add nu_plugin_inc
    plugin use inc
  8. New features in Nushell 0.76

    main

    Nushell 0.76 introduced several key improvements to language syntax, command organization, and error handling:

    • String and List Multiplication: You can now use the multiplication operator (*) to repeat strings and lists.
    • Command Separation: Dataframe commands are now explicitly separated from core Nushell commands.
    • Case Sensitivity: Clarification/changes regarding PATH vs Path usage.
    • Plugin Improvements: More commands have been moved to the plugin system, and plugins now receive first-class help support.
    • Improved Error Messages: Enhanced error reporting for:
      • int and string literals
      • Invalid 2-character escapes
      • Invalid unicode escapes
  9. Use the spread operator for lists and records

    main

    The spread operator (...) allows you to unpack the elements of a list or the key-value pairs of a record into a new list or record literal. This is useful for avoiding explicit append or merge calls.

    Rules:

    • There must be no whitespace between the ... and the expression being spread.
    • You can spread variables, subexpressions, and literals.
    • Currently, spreading arguments to commands is not yet implemented.
    # Spreading in lists
    let list = ["foo"]
    [
        1,
        ...$list,
        ...("foo" | split chars),
        ...[3 9],
        []
    ]
    
    # Spreading in records
    let record = { a: "foo" }
    {
        ...$record,
        y: "bar",
        ...{ z: 2 }
    }
  10. Plugin protocol overhaul in Nushell 0.91.0

    main

    The plugin protocol has been redesigned to support streaming plugins that operate on data streams.

    For Plugin Developers (Rust)

    • A new StreamingPlugin trait is available in the nu-plugin crate for implementing stream-based functionality.
    • Existing Rust plugins do not require logic changes but must be recompiled with the latest version of nu-plugin to be compatible with the new protocol.

    Key Protocol Improvements

    • Version Compatibility: Plugins now automatically refuse to run if they are incompatible with the current Nushell version, providing clearer error messages.
    • Nested Custom Values: Plugin custom values can now be nested within other values and used as arguments, rather than being restricted to top-level input/output.
    • Lifecycle Management: Plugins are expected to remain running until Nushell explicitly signals them to stop.
    • Bidirectional Communication: The protocol provides more abstract communication, allowing for tighter integration between plugins and the Nushell engine.
  11. Stricter rules for setting environment variables

    main

    Nushell now enforces stricter rules to prevent the modification of special environment variables controlled by the system.

    Prohibited Variables

    You can no longer change the following special environment variables via $env.VAR_NAME assignment, with-env, the FOO=bar command shorthand, or load-env:

    • $env.PWD
    • $env.FILE_PWD
    • $env.CURRENT_FILE

    Shorthand Syntax Restrictions

    The FOO=bar BAZ=bla command shorthand syntax no longer allows repeating the same environment variable name. Doing so will now raise an error.

    # Now raises an error
    FOO=bar FOO=bla command