Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

is-redirected for platform

Check if the current custom command's return value is redirected away from display.

Signature

> is-redirected {flags}

Input/output types:

inputoutput
nothingbool

Examples

Inside a custom command, report if the call's return value is redirected (works in if).

> def pipetest [] { if (is-redirected) { "piped" } else { "display" } }; pipetest

Return true when the custom command is piped to another command.

> def pipetest [] { is-redirected }; pipetest | $in
true

Return true when the custom command result is collected into a variable.

> def pipetest [] { is-redirected }; let x = (pipetest); $x
true

Notes

This is a Nushell pipeline-destination check, not an OS TTY check.

Inside a custom command, is-redirected reports if that command's return value will be piped to another command, collected into a value (let, subexpression), written to a file, or discarded — as opposed to being printed via the normal display path.

Unlike looking at process stdout, this is stable for the entire command body, so it works inside if (...) and let x = (...).

To test if process stdout is a terminal (scripts: ./script | cat), use is-terminal --stdout instead.

Typical pattern for pretty-vs-data custom commands:

def mycmd [] {
  if (is-terminal --stdout) and not (is-redirected) {
    # human-friendly formatting
  } else {
    # structured data for pipelines
  }
}