### Install Rust via rustup (Example) Source: https://www.nushell.sh/book/installation Example output from the rustup installer, showing the default installation options for the Rust toolchain. Users are prompted to choose between proceeding with the default installation, customizing it, or canceling. ```shell Current installation options: default host triple: x86_64-unknown-linux-gnu default toolchain: stable profile: default modify PATH variable: yes 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation ``` -------------------------------- ### Run Nushell Binary Source: https://www.nushell.sh/book/installation This snippet shows how to launch the Nushell interactive shell from the command line. After installation, typing 'nu' will start the shell, indicated by a prompt like '/home/sophiajt/Source>'. ```shell $ nu /home/sophiajt/Source> ``` -------------------------------- ### Install and Use a NuShell Plugin (Shell Commands) Source: https://www.nushell.sh/contributor-book/plugins These shell commands demonstrate how to install a NuShell plugin using Cargo and then add and use it within a NuShell session. It covers building the plugin, installing it, and registering it with NuShell using `plugin add` and `plugin use` commands. The example also shows how to verify the plugin's functionality and access its help information. ```shell > cargo install --path . --locked # nushell only (run with `nu -c` if not in nushell) > plugin add ~/.cargo/bin/nu_plugin_len # add .exe on Windows > plugin use len # the name of the plugin (without `nu_plugin_`) nu "hello" | len # => 5 help len # => calculates the length of its input # => # => Usage: # => > len # => # => Flags: # => -h, --help - Display the help message for this command # => # => Signatures: # => | len -> ``` -------------------------------- ### Nushell `take` command examples Source: https://www.nushell.sh/commands/docs/take Demonstrates how to use the `take` command in Nushell to get the first N elements from different data types like lists, tables, and binary values. It shows basic usage and specific examples for each data type. ```nushell > [1 2 3] | take 1 ╭───┬───╮ │ 0 │ 1 │ ╰───┴───╯ ``` ```nushell > [1 2 3] | take 2 ╭───┬───╮ │ 0 │ 1 │ │ 1 │ 2 │ ╰───┴───╯ ``` ```nushell > [[editions]; [2015] [2018] [2021]] | take 2 ╭───┬──────────╮ │ # │ editions │ ├───┼──────────┤ │ 0 │ 2015 │ │ 1 │ 2018 │ ╰───┴──────────╯ ``` ```nushell > 0x[01 23 45] | take 2 Length: 2 (0x2) bytes | printable whitespace ascii_other non_ascii 00000000: 01 23 •# ``` ```nushell > 1..10 | take 3 ╭───┬───╮ │ 0 │ 1 │ │ 1 │ 2 │ │ 2 │ 3 │ ╰───┴───╯ ``` -------------------------------- ### Nushell Welcome Message Example Source: https://www.nushell.sh/blog/2020-01-28-nushell-0_9_0 An example of the welcome message displayed when Nushell version 0.9.0 starts. It shows the Nu version, operating system, and Rust toolchain version. ```nushell Welcome to Nushell 0.9.0 (type 'help' for more info) nushell on 📙 bump_to_0_9_0 is 📦 v0.9.0 via 🦀 v1.40.0 ❯ ``` -------------------------------- ### Opening Non-HTTP URIs with 'start' in Nushell Source: https://www.nushell.sh/blog/2025-02-04-nushell_0_102_0 Illustrates the enhanced 'start' command in Nushell, which now supports non-HTTP URIs. This example shows how to use 'start' with a Spotify URI to play a track, leveraging system-specific openers. ```nushell start spotify:track:4PTG3Z6ehGkBFwjybzWkR8?si=f9b4cdfc1aa14831 ``` -------------------------------- ### Nushell `start` Command Source: https://www.nushell.sh/commands/docs/start The `start` command is used to open a specified path (file, folder, or URL) with its default application or viewer. ```APIDOC ## `start` ### Description Opens a folder, file, or website in the default application or viewer. ### Method Nushell Command ### Endpoint `start {flags} (path)` ### Parameters #### Path Parameters - **path** (string) - Required - Path or URL to open. ### Request Example ``` > start file.txt > start https://www.nushell.sh > start . ``` ### Response #### Success Response (200) - **output** (any) - The result of the operation, typically nothing upon successful execution. #### Response Example ```json { "example": null } ``` ``` -------------------------------- ### Add Command Examples with `attr example` in NuShell Source: https://www.nushell.sh/blog/2025-03-18-nushell_0_103_0 Demonstrates how to attach example usage to a NuShell command's help text using the `attr example` command. This improves command discoverability and understanding by providing runnable examples directly in the help output. ```nushell @example "double an int" { 5 | double } --result 10 @example "double a float" { 0.5 | double } --result 1.0 def double []: [number -> number] { $in * 2 } # The examples above will be shown in `help double` or `double --help`. ``` -------------------------------- ### Render table with index starting from 1 Source: https://www.nushell.sh/commands/docs/table This example demonstrates how to list files in the current directory and display them in a table format with the index column starting from 1. It utilizes the `ls` command piped to `table` with the `--index` flag. ```nushell > ls | table --index 1 ``` -------------------------------- ### Open Files, Folders, and URLs with `start` in Nushell Source: https://www.nushell.sh/commands/docs/start The `start` command in Nushell opens a specified path or URL using the default application. It takes a single parameter, `path`, which can be a local file, directory, a web URL, or an application-specific protocol URL. It does not produce any output. ```nushell > start file.txt > start file.jpg > start . > start file.pdf > start https://www.nushell.sh > start obsidian://open?vault=Test ``` -------------------------------- ### Install Nushell with Winget (Windows) Source: https://www.nushell.sh/book/installation Commands for installing and upgrading Nushell using the Winget package manager on Windows. It includes options for both machine-wide and user-specific installations and upgrades, with a workaround for a known upgrade issue. ```shell winget install nushell --scope machine winget update nushell winget install nushell --scope user winget install nushell ``` -------------------------------- ### Start Nushell Language Server Source: https://www.nushell.sh/blog/2023-11-14-nushell_0_87_0 This command starts the Nushell Language Server (LSP) directly from the shell. The LSP enables IDEs to provide features like diagnostics, code completion, and more for Nushell scripts. It requires no external installation when Nushell is properly configured. ```shell nu --lsp ``` -------------------------------- ### Example of `first` Command Usage in Nushell Source: https://www.nushell.sh/book/pipelines Illustrates the usage of the `first` command with different input types (list and range) and shows its output. This example is derived from the `help first` output. ```nushell [a b c] | first ``` ```nushell 1..4 | first ``` -------------------------------- ### Install Nushell Plugins Source: https://www.nushell.sh/blog/2020-01-28-nushell-0_9_0 Guide on how to install Nushell plugins using Cargo. Each plugin is installed individually using its specific package name. ```bash cargo install nu_plugin_ ``` -------------------------------- ### Nushell: Get the first item from a range Source: https://www.nushell.sh/commands/docs/first This example demonstrates using the `first` command in Nushell to obtain the initial value from a numerical range. This is useful for quickly accessing the starting point of a sequence. ```nushell > 1..3 | first 1 ``` -------------------------------- ### Install Nushell from crates.io using Cargo Source: https://www.nushell.sh/book/installation Installs the latest Nushell release from crates.io using the Cargo package manager. Cargo handles downloading, building, and installing Nu and its source dependencies. Note: Default plugins require separate installation. ```bash cargo install nu --locked ``` -------------------------------- ### Install Nushell with npm Source: https://www.nushell.sh/book/installation Command to install Nushell globally using npm. Note that this method may not include Nushell plugins. ```shell npm install -g nushell ``` -------------------------------- ### Nushell http: Get content from example.com Source: https://www.nushell.sh/commands/docs/http Fetches content from a given URL using the default HTTP verb (GET). This is a basic usage example for retrieving data from a web resource. ```nushell > http https://www.example.com ``` -------------------------------- ### Get Help for Nushell Commands Source: https://www.nushell.sh/book/quick_tour Provides examples of how to access Nushell's in-shell help system for commands, operators, and escapes using the 'help' command or command-specific flags like '--help'. ```nushell # help help ls # Or ls --help # Also help operators help escapes ``` -------------------------------- ### Benchmarking with Multiple Closures and Flags Source: https://www.nushell.sh/blog/2025-06-10-nushell_0_105_0 This example showcases the enhanced `bench` command in Nushell, which now supports passing multiple closures for comparison. It also demonstrates the use of various flags like `--warmup`, `--setup`, `--prepare`, `--cleanup`, `--conclude`, and `--ignore-errors` for fine-grained control over benchmarking. This allows for more comprehensive performance analysis. ```nushell # Example usage with multiple closures and flags: bench --warmup 5 --setup { echo 'Setup complete' } { "Closure 1" | do_something } { "Closure 2" | do_something_else } ``` -------------------------------- ### Start Multiple Files with Glob Paths in Nushell Source: https://www.nushell.sh/blog/2020-06-09-nushell_0_15_0 Demonstrates the `start` command in Nushell now supporting glob paths, allowing multiple files to be passed as arguments at once. ```nushell > start file*.rs ``` -------------------------------- ### Python Exec Example: Function Definition Source: https://www.nushell.sh/book/how_nushell_code_gets_run Illustrates how Python's exec() function can define and execute functions dynamically. This example defines a 'hello' function and then calls it, demonstrating how code can be introduced during interpretation. ```python exec("def hello(): print('Hello eval!')") hello() ``` -------------------------------- ### Explore Nushell Configuration with Example Data Source: https://www.nushell.sh/commands/docs/explore_config Launches the nushell configuration TUI using example data instead of the actual configuration file. This is helpful for understanding the TUI's features and capabilities without modifying the live configuration. ```nushell > explore config --use-example-data ``` -------------------------------- ### Example of source command with string interpolation Source: https://www.nushell.sh/blog/2025-12-02-nushell_v0_109_1 This example demonstrates the corrected usage of the `source` command with bare-word string interpolation for configuration files. It shows how to dynamically load a configuration file based on the operating system name. ```nushell source config/($nu.os-info.name).nu ``` -------------------------------- ### Install Nushell on Debian/Ubuntu Source: https://www.nushell.sh/book/installation Shell commands to add the Nushell APT repository and install Nushell on Debian-based systems like Ubuntu. This involves adding a GPG key, configuring the repository, updating package lists, and then installing the package. ```shell wget -qO- https://apt.fury.io/nushell/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/fury-nushell.gpg echo "deb [signed-by=/etc/apt/keyrings/fury-nushell.gpg] https://apt.fury.io/nushell/ /" | sudo tee /etc/apt/sources.list.d/fury-nushell.list sudo apt update sudo apt install nushell ``` -------------------------------- ### Install Nushell on Alpine Linux Source: https://www.nushell.sh/book/installation Shell commands to add the Nushell APK repository and install Nushell on Alpine Linux. This includes appending the repository URL to the sources list, updating the package index, and installing the package, allowing untrusted packages if necessary. ```shell echo "https://alpine.fury.io/nushell/" | tee -a /etc/apk/repositories apk update apk add --allow-untrusted nushell ``` -------------------------------- ### String Expansion Example (Nushell) Source: https://www.nushell.sh/blog/2023-08-22-nushell_0_84_0 Provides an example of the `str expand` command, highlighting its utility for string manipulation. This command is recommended for checking out due to its usefulness. ```nushell # Example usage for str expand (actual command syntax may vary) let template = "Hello, {{name}}!" str expand $template --params {name: "World"} ``` -------------------------------- ### Unified 'start' Command for Opening Files in Nushell Source: https://www.nushell.sh/blog/2020-05-12-nushell_0_14_0 Illustrates the usage of the new unified 'start' command in Nushell, which opens files using their associated default applications across different operating systems. This command simplifies file interaction by abstracting platform-specific commands like 'open' or 'start'. ```nushell > start myfile.py ``` -------------------------------- ### Add Example Attribute to Nushell Command Source: https://www.nushell.sh/book/custom_commands Enhances the 'vip-greet' custom command by adding an 'example' attribute using the '@' prefix. This attribute provides usage examples that appear in the command's help output. ```nushell # Greet guests along with a VIP # # Use for birthdays, graduation parties, # retirements, and any other event which # celebrates an event # for a particular @"example" "vip-greet 'Alice' 'Bob' 'Charlie'" def vip-greet [ vip: string # The special guest ...names: string # The other guests ] { for $name in $names { print $"Hello, ($name)!" } print $"And a special welcome to our VIP today, ($vip)!" } ``` -------------------------------- ### Add Examples to Custom Nushell Commands Source: https://www.nushell.sh/commands/docs/attr_example Demonstrates how to use the `attr example` command to add descriptive examples to custom Nushell commands. This includes specifying the example code and its expected output. ```nushell > # Double numbers @example "double an int" { 2 | double } --result 4 @example "double a float" { 0.25 | double } --result 0.5 def double []: [number -> number] { $in * 2 } ``` -------------------------------- ### Run Nushell Docker Container (Specific Command) Source: https://www.nushell.sh/book/installation Command to execute a specific Nushell command within a Docker container. This example lists files in '/usr/bin' that are larger than 10KiB. ```shell docker run --rm ghcr.io/nushell/nushell:latest-alpine -c "ls /usr/bin | where size > 10KiB" ``` -------------------------------- ### Build and Run Nushell from GitHub Repository (Release Mode) Source: https://www.nushell.sh/book/installation Builds and runs Nushell from the cloned GitHub repository in release mode, enabling optimizations. Similar to debug mode, this ensures all plugins are built. ```bash cargo build --release --workspace; cargo run --release ``` -------------------------------- ### Install Build Dependencies on macOS with Homebrew Source: https://www.nushell.sh/book/installation Homebrew commands to install 'openssl' and 'cmake', which are required dependencies for building Nushell on macOS. ```shell brew install openssl cmake ``` -------------------------------- ### Run Nushell Tutorial Source: https://www.nushell.sh/commands/docs/tutor Initiates the Nushell interactive tutorial. This is the primary command to start learning Nushell features. No specific input is required to begin. ```nushell > tutor begin ``` -------------------------------- ### Check if bytes start with a pattern (Nushell) Source: https://www.nushell.sh/commands/docs/bytes_starts-with This example demonstrates how to use the `bytes starts-with` command in Nushell to check if a binary value begins with a specific byte pattern. It takes a binary input and a pattern as arguments, returning `true` if the pattern matches the beginning of the binary data, and `false` otherwise. ```nushell > 0x[1F FF AA AA] | bytes starts-with 0x[1F FF AA] true ``` ```nushell > 0x[1F FF AA AA] | bytes starts-with 0x[1F] true ``` ```nushell > 0x[1F FF AA AA] | bytes starts-with 0x[11] false ``` -------------------------------- ### Test Plugin Examples Automatically (Rust) Source: https://www.nushell.sh/contributor-book/plugins This snippet demonstrates how to automatically test the examples defined for a Nushell plugin command using the `nu-plugin-test-support` crate. It requires the `nu_protocol`, `nu_plugin`, and `nu_plugin_test_support` crates. The test function `test_examples` uses `PluginTest::new` and `test_examples` to verify the plugin's example outputs. ```rust use nu_protocol::{Example, ShellError, Value}; use nu_plugin::PluginCommand; struct FibPlugin; struct Fib; // ... impl PluginCommand for Fib { type Plugin = FibPlugin; fn name(&self) -> &str { "fib" } // ... fn examples(&self) -> Vec { vec![ Example { example: "fib 20", description: "Compute the 20th Fibonacci number", result: Some(Value::test_int(6765)) }, ] } // ... } #[test] fn test_examples() -> Result<(), ShellError> { use nu_plugin_test_support::PluginTest; PluginTest::new("fib", FibPlugin.into())?.test_examples(&Fib) } ``` -------------------------------- ### Describe String Type in Nushell Source: https://www.nushell.sh/commands/docs/describe Demonstrates how to use the 'describe' command to get the type of a string. It takes a string as input and outputs its type. ```nushell > 'hello' | describe string ``` -------------------------------- ### Plugin Help and Usage Display Source: https://www.nushell.sh/blog/2023-11-14-nushell_0_87_0 Demonstrates how plugins can expose extra usage information and search terms when the `--help` command is invoked. This helps users understand plugin capabilities and how to use them effectively. ```nushell PluginSignature test 1 for plugin. Returns Value::Nothing Extra usage for nu-example-1 Search terms: example Usage: > nu-example-1 {flags} (opt) ...(rest) Flags: -h, --help - Display the help message for this command -f, --flag - a flag for the signature -n, --named - named string Parameters: a : required integer value b : required string value opt : Optional number (optional) ...rest : rest value string Examples: running example with an int value and string value > nu-example-1 3 bb ``` -------------------------------- ### Install Build Dependencies on Debian/Ubuntu Source: https://www.nushell.sh/book/installation APT command to install essential packages required for building software, including Nushell, on Debian-based systems. It installs 'pkg-config', 'build-essential', and 'libssl-dev'. ```shell apt install pkg-config libssl-dev build-essential ``` -------------------------------- ### Prepare Plugin Registry File for Scripts Source: https://www.nushell.sh/blog/2024-04-30-nushell_0_93_0 Ensures a plugin is available in a script by preparing a plugin registry file and using `--plugin-config` with `plugin use`. This method is suitable for pre-script setup. ```nushell plugin use --plugin-config /path/to/custom.msgpackz your_required_plugin ``` -------------------------------- ### Install Nushell with Scoop (Windows) Source: https://www.nushell.sh/book/installation Command to install Nushell using the Scoop package manager on Windows. This is a straightforward command for adding Nushell to your system. ```shell scoop install nu ``` -------------------------------- ### Nushell ulimit Command Example Source: https://www.nushell.sh/blog/2024-01-09-nushell_0_89_0 Demonstrates the usage of the new `ulimit` command in Nushell for Unix-based systems. It shows how to list current resource limits and mentions that setting limits is done via flags available in `help ulimit`. ```nushell # To list the current limits: ulimit -a # Setting the limits is done via flags available in `help ulimit`. ``` -------------------------------- ### Install Build Dependencies on RHEL-based Distros Source: https://www.nushell.sh/book/installation YUM/DNF command to install necessary development packages for building software on RHEL-based systems like Fedora or Rocky Linux. It installs 'libxcb', 'openssl-devel', and 'libX11-devel'. ```shell yum install libxcb openssl-devel libX11-devel ``` -------------------------------- ### Extract Filenames and Echo with NuShell Source: https://www.nushell.sh/blog/2019-08-23-introducing-nushell This example demonstrates how to extract filenames from a directory listing using NuShell's `ls` and `get name` commands, and then pass these names to an external command like `echo` using `$it`. This showcases inter-process communication. ```nushell > ls | get name | echo $it ``` -------------------------------- ### Nushell Command Syntax Examples Source: https://www.nushell.sh/blog/2020-08-23-year_of_nushell Illustrates different ways to write commands in Nushell, showing the difference between a concise syntax and a more explicit canonical form using block syntax. ```nushell where size > 10kb ``` ```nushell where { = $it.size > 10kb } ``` -------------------------------- ### Install Nushell on RedHat/Fedora/Rocky Linux Source: https://www.nushell.sh/book/installation Shell commands to set up the Nushell DNF/YUM repository and install Nushell on Red Hat-based Linux distributions. This involves creating a repository configuration file and then installing the package using dnf. ```shell echo "[gemfury-nushell] name=Gemfury Nushell Repo baseurl=https://yum.fury.io/nushell/ enabled=1 gpgcheck=0 gpgkey=https://yum.fury.io/nushell/gpg.key" | sudo tee /etc/yum.repos.d/fury-nushell.repo sudo dnf install -y nushell ``` -------------------------------- ### Build and Run Nushell from GitHub Repository (Debug Mode) Source: https://www.nushell.sh/book/installation Builds and runs Nushell from the cloned GitHub repository in debug mode. This process ensures all plugins are built, addressing a current Cargo default-run option limitation. ```bash cd nushell # ./nushell cargo build --workspace; cargo run ``` -------------------------------- ### Clone Nushell Documentation Repository Source: https://www.nushell.sh/CONTRIBUTING This command clones the Nushell documentation repository locally. It's a one-time setup step required before starting development. ```bash git clone git@github.com:nushell/nushell.github.io.git nu-docs ``` -------------------------------- ### Write Plugin Example Tests with PluginTest Source: https://www.nushell.sh/blog/2024-04-02-nushell_0_92_0 This Rust code demonstrates how to use the 'PluginTest' struct from the 'nu-plugin-test-support' crate to write tests for your plugin's command examples. It requires initializing 'PluginTest' with the plugin name and instance, then calling 'test_command_examples'. ```rust #[test] fn test_examples() -> Result<(), nu_protocol::ShellError> { use nu_plugin_test_support::PluginTest; PluginTest::new("my_plugin", MyPlugin.into())?.test_command_examples(&MyCommand) } ``` -------------------------------- ### Nushell REPL: Basic Commands Source: https://www.nushell.sh/book/how_nushell_code_gets_run Shows examples of interacting with the Nushell Read-Eval-Print Loop (REPL). It includes a simple print command and the 'ls' command to list directory contents. ```nushell > print "Hello world!" # => Hello world! > ls ``` -------------------------------- ### Using 'select' to Access Nushell Table Data Structure Source: https://www.nushell.sh/book/navigating_structured_data Explains and demonstrates the 'select' command in Nushell, which differs from 'get' by returning the data structure itself rather than just its value. This example selects the second row. ```nushell $data | select 1 ``` -------------------------------- ### Nushell: Opening compressed tar archives Source: https://www.nushell.sh/blog/2023-10-17-nushell_0_86 Explains how Nushell's `open` command can now handle `tar.gz` files by leveraging the `from` command's ability to manage multiple file extensions. ```nushell # Assuming 'from tar.gz' and 'from gz' are defined open foo.tar.gz ``` -------------------------------- ### Set starting number for index column Source: https://www.nushell.sh/commands/docs/table This example shows how to set a custom starting number for the index column using the `-i` flag followed by the desired integer. ```nushell > [[a b]; [1 2] [3 [4 4]]] | table -i 100 ``` -------------------------------- ### Nushell merge Command Examples with Output Source: https://www.nushell.sh/blog/2023-03-14-nushell_0_77 Demonstrates the `merge` command in Nushell, showcasing how examples now include their expected output directly within the help documentation. This applies to merging tables and records. ```nushell Examples: Add an 'index' column to the input table > [a b c] | wrap name | merge ( [1 2 3] | wrap index ) ╭───┬──────╮ │ # │ name │ ├───┼──────┤ │ 1 │ a │ │ 2 │ b │ │ 3 │ c │ ╰───┴──────╯ Merge two records > {a: 1, b: 2} | merge {c: 3} ╭───┬───╮ │ a │ 1 │ │ b │ 2 │ │ c │ 3 │ ╰───┴───╯ Merge two tables, overwriting overlapping columns > [{columnA: A0 columnB: B0}] | merge [{columnA: 'A0*'}] ╭───┬─────────┬─────────╮ │ # │ columnA │ columnB │ ├───┼─────────┼─────────┤ │ 0 │ A0* │ B0 │ ╰───┴─────────┴─────────╯ ``` -------------------------------- ### Join Plugin List with Process Information Source: https://www.nushell.sh/blog/2024-04-02-nushell_0_92_0 This example demonstrates how to combine the output of 'plugin list' with the 'ps' command using the 'join' command on the 'pid' column. This allows for detailed inspection of running plugins, such as their memory usage. ```nushell > plugin list | join (ps) pid | select name pid mem ╭───┬───────┬────────┬──────────╮ │ # │ name │ pid │ mem │ ├───┼───────┼────────┼──────────┤ │ 0 │ gstat │ 741572 │ 10.2 MiB │ │ 1 │ inc │ 741577 │ 3.6 MiB │ ╰───┴───────┴────────┴──────────╯ ``` -------------------------------- ### Python Eval Example: Hello World Source: https://www.nushell.sh/book/how_nushell_code_gets_run Demonstrates the basic usage of the eval() function in Python to execute a string as code. Running this script prints two messages: 'Hello, World!' and 'Hello, Eval!'. ```python print("Hello, World!") eval("print('Hello, Eval!')") ``` -------------------------------- ### Checking Command Input/Output Types with `help` in Nushell Source: https://www.nushell.sh/book/pipelines Shows how to use the `help` command to inspect a command's supported input and output types, which is crucial for understanding how it can be integrated into pipelines. Provides examples for `first` and `ls`. ```nushell help first ``` ```nushell help ls ``` ```nushell help sleep ``` -------------------------------- ### Display help for `nu --testbin` in Nushell Source: https://www.nushell.sh/blog/2025-09-02-nushell_0_107_0 This command shows the available subcommands for `nu --testbin`. It lists various test binaries with brief descriptions of their functionality and example usage. This is useful for testing Nushell's external command execution. ```Nushell > nu --testbin -h Usage: nu --testbin : chop -> With no parameters, will chop a character off the end of each line cococo -> Cross platform echo using println!();(e.g: nu --testbin cococo a b c) echo_env -> Echo's value of env keys from args(e.g: nu --testbin echo_env FOO BAR) echo_env_mixed -> Mix echo of env keys from input(e.g: nu --testbin echo_env_mixed out-err FOO BAR; nu --testbin echo_env_mixed err-out FOO BAR) echo_env_stderr -> Echo's value of env keys from args to stderr(e.g: nu --testbin echo_env_stderr FOO BAR) echo_env_stderr_fail -> Echo's value of env keys from args to stderr, and exit with failure(e.g: nu --testbin echo_env_stderr_fail FOO BAR) fail -> Exits with failure code 1(e.g: nu --testbin fail) iecho -> Another type of echo that outputs a parameter per line, looping infinitely(e.g: nu --testbin iecho 3) input_bytes_length -> Prints the number of bytes received on stdin(e.g: 0x[deadbeef] | nu --testbin input_bytes_length) meow -> Cross platform cat (open a file, print the contents) using read_to_string and println!();(e.g: nu --testbin meow file.txt) meowb -> Cross platform cat (open a file, print the contents) using read() and write_all() / binary(e.g: nu --testbin meowb sample.db) nonu -> Cross platform echo but concats arguments without space and NO newline(e.g: nu --testbin nonu a b c) nu_repl -> Run a REPL with the given source lines, it must be called with `--testbin=nu_repl`, `--testbin nu_repl` will not work due to argument count logic relay -> Relays anything received on stdin to stdout(e.g: 0x[beef] | nu --testbin relay) repeat_bytes -> A version of repeater that can output binary data, even null bytes(e.g: nu --testbin repeat_bytes 003d9fbf 10) repeater -> Repeat a string or char N times(e.g: nu --testbin repeater a 5) ``` -------------------------------- ### Nushell Block Example (Loop) Source: https://www.nushell.sh/contributor-book/philosophy_0_80 Provides an example of a block in Nushell, used here within a `for` loop to execute a command for a range of numbers. Blocks are not first-class values and are run by commands. ```nushell for x in 1..100 { print $x } ``` -------------------------------- ### Nushell Script with Parameters Source: https://www.nushell.sh/book/scripts Shows how to create a Nushell script that accepts parameters. The example defines a `main` command that takes an integer `x` as input and adds 10 to it. ```Nushell # myscript.nu def main [x: int] { $x + 10 } ``` ```Nushell nu myscript.nu 100 ``` -------------------------------- ### Nushell: Accessing HTTP Response Status Metadata Source: https://www.nushell.sh/book/metadata Demonstrates how HTTP commands in Nushell automatically attach response metadata. This example shows retrieving the HTTP status code from a GET request to an example API. ```nushell http get https://api.example.com | metadata | get http_response.status # => 200 ``` -------------------------------- ### Nushell `try` Command Examples Source: https://www.nushell.sh/commands/docs/try Demonstrates the usage of the Nushell `try` command for error handling. It shows how to execute a block and optionally provide a catch closure to handle errors, such as division by zero. The examples illustrate returning a default string or reporting the error message. ```nushell > try { 1 / 0 } ``` ```nushell > try { 1 / 0 } catch { 'divided by zero' } divided by zero ``` ```nushell > try { 1 / 0 } catch { |err| $err.msg } ``` -------------------------------- ### Nushell: Get the first N bytes of binary data Source: https://www.nushell.sh/commands/docs/first This example illustrates retrieving a specified number of initial bytes from binary data using the `first` command in Nushell. The output format displays the length and the hexadecimal representation of the retrieved bytes. ```nushell > 0x[01 23 45] | first 2 Length: 2 (0x2) bytes | printable whitespace ascii_other non_ascii 00000000: 01 23 •# ``` -------------------------------- ### Case-Sensitive Field Extraction with `get` in Nushell Source: https://www.nushell.sh/commands/docs/get Demonstrates attempting to retrieve an environment variable using case-sensitive matching. This example highlights that a case mismatch, like 'Path' instead of 'PATH', will result in no data being returned. ```nushell > $env | get Path ``` -------------------------------- ### Enabling All Experimental Options (Nushell) Source: https://www.nushell.sh/blog/2025-10-15-nushell_v0_108_0 Demonstrates how to enable all available experimental options in Nushell using either the command-line argument or the environment variable with the value `all`. ```nushell nu --experimental-options '[all]' ``` ```nushell NU_EXPERIMENTAL_OPTIONS="all" nu ``` -------------------------------- ### NUON Data Structure Example Source: https://www.nushell.sh/book/loading_data Provides an example of Nushell Object Notation (NUON) syntax, which is used for configuration files in Nushell. NUON is a superset of JSON, allowing for comments and optional commas, making it more human-friendly. This example shows a configuration for menus. ```nushell { menus: [ # Configuration for default nushell menus # Note the lack of source parameter { name: completion_menu only_buffer_difference: false marker: "| " type: { layout: columnar columns: 4 col_width: 20 # Optional value. If missing all the screen width is used to calculate column width col_padding: 2 } style: { text: green selected_text: green_reverse description_text: yellow } } ] } ``` -------------------------------- ### Python Eval Example Source: https://www.nushell.sh/book/how_nushell_code_gets_run Demonstrates the 'eval' function in Python, where source code is evaluated dynamically during runtime. ```python x = 10 print(eval('x + 5')) ``` -------------------------------- ### Nushell: Environment Loading Example (0.32) Source: https://www.nushell.sh/blog/2021-06-01-nushell_0_32 Provides an example of Nushell's environment loading feature in 0.32, where environment changes are returned as a table. ```nushell def activate [] { [[name, value]; [FOO, BAR] [DEBUG, TRUE] [CURRENTENV, NUSHELL]] } load-env (activate) echo $nu.env.FOO ``` -------------------------------- ### Using 'get' to Access Nushell Table Data Source: https://www.nushell.sh/book/navigating_structured_data Explains and demonstrates the 'get' command in Nushell, which is an alternative to cell-path literals for accessing data. It returns the value at the specified path. This example retrieves the second row. ```nushell $data | get 1 ``` -------------------------------- ### Configure Startup Banner Theming in Nushell Source: https://www.nushell.sh/blog/2025-03-18-nushell_0_103_0 Allows customization of the Nushell startup banner's appearance using color configuration settings. Define foreground and highlight colors to style the welcome message. These settings are part of the `$env.config.color_config` object. ```nushell # Example configuration (actual values would be set by the user) $env.config.color_config = { banner_foreground: "blue" banner_highlight1: "green" banner_highlight2: "yellow" } ``` -------------------------------- ### Nushell `match` examples Source: https://www.nushell.sh/commands/docs/match Demonstrates various ways to use the `match` command in Nushell for conditional execution based on different patterns. This includes matching simple values, ranges, records, lists, pipeline input, and using guards for complex conditions. ```nushell > match 3 { 1 => 'one', 2 => 'two', 3 => 'three' } three ``` ```nushell > match 'three' { 1 | 'one' => '-', 2 | 'two' => '--', 3 | 'three' => '---' } --- ``` ```nushell > match 3 { 1..10 => 'yes!' } yes! ``` ```nushell > match {a: 100} { {a: $my_value} => { $my_value } } 100 ``` ```nushell > match 3 { 1 => { 'yes!' }, _ => { 'no!' } } yes! ``` ```nushell > match [1, 2, 3] { [$a, $b, $c] => { $a + $b + $c }, _ => 0 } 6 ``` ```nushell > {a: {b: 3}} | match $in {{a: { $b }} => ($b + 10) } 13 ``` ```nushell > match [1 2 3] { [$x, ..$y] if $x == 1 => { 'good list' }, _ => { 'not a very good list' } } good list ``` -------------------------------- ### Get Types of Multiple Filepaths with Nushell `path type` Source: https://www.nushell.sh/commands/docs/path_type This example shows how to get the types of multiple filepaths by piping the output of `ls` (listing directory contents) and `get name` (extracting names) into the `path type` command. It accepts a list of strings (filenames) and outputs a list of strings representing their types. ```nushell > ls | get name | path type ``` -------------------------------- ### Find first occurrence of byte pattern in bytes Source: https://www.nushell.sh/commands/docs/bytes_index-of This example demonstrates how to find the starting index of the first occurrence of a specified byte pattern within a binary input. The command takes the byte pattern as an argument. ```nushell > 0x[33 44 55 10 01 13 44 55] | bytes index-of 0x[44 55] 1 ``` -------------------------------- ### Set XDG_CONFIG_HOME for Nushell Configuration Source: https://www.nushell.sh/book/configuration This example demonstrates how to set the XDG_CONFIG_HOME environment variable to a custom directory for Nushell's configuration files. Nushell will then look for files like env.nu, config.nu, and login.nu within the 'nushell' subdirectory of the specified path. This is useful for managing configurations separately. ```nushell # Create an empty temporary directory let temp_home = (mktemp -d) # Set the configuration path to this directory $env.XDG_CONFIG_HOME = $temp_home # Set the data-dir to this directory $env.XDG_DATA_HOME = $temp_home # Remove other potential autoload directories $env.XDG_DATA_HOME = "" # Run Nushell in this environment nu # Edit config config nu # Exit the subshell exit # Run the temporary config nu # Remove the temporary config directory, if desired rm $temp_home ``` -------------------------------- ### Get Unique Values from a Polars Series Source: https://www.nushell.sh/commands/docs/polars_unique This example demonstrates how to get unique values from a Polars series by converting it into a dataframe and then applying the `polars unique` command. It takes a series as input and outputs a dataframe containing only the unique values. ```nushell > [2 2 2 2 2] | polars into-df | polars unique ╭───┬───╮ │ # │ 0 │ ├───┼───┤ │ 0 │ 2 │ ╰───┴───╯ ``` -------------------------------- ### Configure Startup Commands in Nushell Source: https://www.nushell.sh/blog/2020-04-21-nushell_0_13_0 Shows how to set up commands that automatically run when Nushell starts. This is particularly useful for loading custom aliases or configurations, ensuring a personalized shell environment from the outset. The `startup` config variable accepts a table of strings, each representing a command to execute. ```nushell > config --set [startup ["alias myecho [msg] { echo $msg }"]] ``` -------------------------------- ### Explore System Host Information (Nushell) Source: https://www.nushell.sh/commands/docs/explore This example demonstrates how to pipe the output of the `sys host` command into `explore` to view system host information in a paginated format. ```nushell > sys host | explore ``` -------------------------------- ### View Nushell Configuration Documentation Source: https://www.nushell.sh/book/configuration This command displays detailed documentation for Nushell's configuration options, including available settings and their descriptions. The output is highlighted and can be piped to a pager like `less` for easier viewing. ```nushell config nu --doc | nu-highlight | less -R ``` -------------------------------- ### Get Cursor Position using Nushell `term query` Source: https://www.nushell.sh/commands/docs/term_query This example demonstrates how to get the cursor position from the terminal using the `term query` command. It specifies the `ansi cursor_position` as the query, with `ansi csi` as the prefix and 'R' as the terminator. ```nushell > term query (ansi cursor_position) --prefix (ansi csi) --terminator 'R' ``` -------------------------------- ### Get Command History Length (Nushell) Source: https://www.nushell.sh/commands/docs/history This example demonstrates how to get the current command history length using the `history` command piped to the `length` command. It takes no explicit input and outputs a single integer representing the history count. ```nushell > history | length ``` -------------------------------- ### Get First List Values in Nushell Source: https://www.nushell.sh/book/cheat_sheet Retrieves a specified number of elements from the beginning of a list. Useful for peeking at the start of a sequence. ```Nushell [cammomile marigold rose forget-me-not] | first 2 ``` -------------------------------- ### Compare Startup Time With and Without Standard Library Source: https://www.nushell.sh/book/standard_library Compares the startup time of Nushell with and without the standard library enabled. This is useful for identifying performance bottlenecks, especially when running commands in a subshell. ```nushell nu --no-std-lib -n -c "$nu.startup-time" # => 1ms 125µs 10ns nu -n -c "$nu.startup-time" # => 4ms 889µs 576ns ``` -------------------------------- ### Nushell `compact` command examples Source: https://www.nushell.sh/commands/docs/compact Demonstrates various use cases of the `compact` command in Nushell, including filtering nulls from records, lists, and specific columns, as well as handling empty items with the `--empty` flag. ```nushell > [["Hello" "World"]; [null 3]] | compact Hello ╭────────────╮ │ empty list │ ╰────────────╯ ``` ```nushell > [["Hello" "World"]; [null 3]] | compact World ╭───┬───────┬───────╮ │ # │ Hello │ World │ ├───┼───────┼───────┤ │ 0 │ │ 3 │ ╰───┴───────┴───────╯ ``` ```nushell > [1, null, 2] | compact ╭───┬───╮ │ 0 │ 1 │ │ 1 │ 2 │ ╰───┴───╯ ``` ```nushell > [1, null, 2, "", 3, [], 4, {}, 5] | compact --empty ╭───┬───╮ │ 0 │ 1 │ │ 1 │ 2 │ │ 2 │ 3 │ │ 3 │ 4 │ │ 4 │ 5 │ ╰───┴───╯ ``` ```nushell > {a: 1, b: null, c: 3} | compact ╭───┬───╮ │ a │ 1 │ │ c │ 3 │ ╰───┴───╯ ``` -------------------------------- ### Get Filepath Type with Nushell `path type` Source: https://www.nushell.sh/commands/docs/path_type This example demonstrates how to use the `path type` command to get the type of the current directory. It takes a string representing the path as input and outputs a string indicating the type (e.g., 'dir'). ```nushell > '.' | path type dir ``` -------------------------------- ### Get PATH Environment Variable with Nushell `debug env` Source: https://www.nushell.sh/commands/docs/debug_env This example demonstrates how to retrieve the value of the PATH environment variable as seen by external commands using Nushell. It pipes the output of `debug env` to the `get` command, specifying 'PATH' as the key. ```nushell > debug env | get PATH! ``` -------------------------------- ### View Nushell Documentation for Configuration Options Source: https://www.nushell.sh/book/configuration Provides commands to view detailed documentation for Nushell's configuration options. This helps users understand available settings and their purposes. The output is highlighted and can be viewed using pagers. ```nushell config nu --doc | nu-highlight | bat ``` ```nushell config nu --doc | nu-highlight | less -R ``` -------------------------------- ### Nushell: Case-insensitive search for files/folders starting with 'c' Source: https://www.nushell.sh/commands/docs/glob This example performs a case-insensitive search for files and folders that begin with the letter 'c'. ```nushell > glob "(?i)c*" ``` -------------------------------- ### Simple Static Completions for Nushell Command Parameters Source: https://www.nushell.sh/blog/2025-10-15-nushell_v0_108_0 Introduces a simpler syntax for defining custom command completions in Nushell. This allows for static lists of options to be directly embedded in command signatures or defined as constants, making it easier to manage common completion scenarios. ```nushell def go [ direction: string@[ left up right down ] ] { $direction } ``` ```nushell const directions = [ left up right down ] def go [ direction: string@$directions ] { $direction } ``` -------------------------------- ### Get user input with file-backed history using Nushell `input` Source: https://www.nushell.sh/commands/docs/input This example demonstrates using a file to store and retrieve command history for user input. The `--history-file` flag specifies the path to the history file, and `--reedline` is implied. ```nushell > let user_input = (input --reedline --history-file ./history.txt) ``` -------------------------------- ### PipelineDataHeader: Single Value Representation Source: https://www.nushell.sh/contributor-book/plugin_protocol_reference Demonstrates the structure for a 'Value' header variant within PipelineDataHeader, which represents a single value and does not start a stream. It includes an example of an 'Int' value. ```json { "Value": { "Int": { "val": 2, "span": { "start": 9090, "end": 9093 } } } } ``` -------------------------------- ### Run a custom command and observe implicit return in Nushell Source: https://www.nushell.sh/book/custom_commands Shows how to execute the 'greet' custom command with the argument 'World' and demonstrates that the command's output is implicitly returned. It also shows piping the output to 'describe' to show its type. ```nushell greet "World" # => Hello, World! greet "World" | describe # => string ```