is-terminal

For platform.

Check if the process stdin, stdout, or stderr is attached to a terminal device.

Command Type

built-in

Signature

> is-terminal {flags}

Flags

  • --stdin, -i: Check if stdin is a terminal.
  • --stdout, -o: Check if stdout is a terminal.
  • --stderr, -e: Check if stderr is a terminal.

Input/output types:

input output
nothing bool

Examples

Check if stdout is a terminal (default when no flag is specified).

> is-terminal

Return “terminal attached” if standard input is attached to a terminal, and “no terminal” if not.

> if (is-terminal --stdin) { "terminal attached" } else { "no terminal" }
terminal attached

Choose formatting based on process stdout being a TTY (works inside if).

> if (is-terminal --stdout) { "human" } else { "piped" }

Notes

This is an operating-system level check (like bash test -t), not a Nushell pipeline check. It reports if the process file descriptor is a TTY, which is what scripts need for ./script.nu | cat vs running on a terminal.

To detect if a custom command’s return value is piped or collected inside Nushell (pretty output vs structured data), use is-redirected instead.

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.