is-redirected for platform
Signature
> is-redirected {flags}
Input/output types:
| input | output |
|---|---|
| nothing | bool |
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" } }; pipetestReturn true when the custom command is piped to another command.
> def pipetest [] { is-redirected }; pipetest | $in
trueReturn true when the custom command result is collected into a variable.
> def pipetest [] { is-redirected }; let x = (pipetest); $x
trueNotes
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
}
}