Skip to content

Fix is-terminal OS detection and add is-redirected for pipeline destinations - #18661

Merged
fdncred merged 3 commits into
nushell:mainfrom
fdncred:is_redirected_is_terminal_update
Jul 18, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
fdncred:is_redirected_is_terminal_update

Conversation

@fdncred

@fdncred fdncred commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR updates/reverts the is-terminal command to it's original state so it can detect ttys and we add a new command is-redirected to determine redirection. We conflated these two commands and it was confusing.

is-terminal (restored)

  • Pure OS checks for --stdin / --stdout / --stderr.
  • No flags defaults to --stdout (kept from Allow is-terminal to detect redirection #18443).
  • Works inside if (…), let, and mid-block again.
  • Help text points users needing Nu pipeline awareness to is-redirected.

is-redirected (new)

  • true when the current custom command’s return value is not going to the interactive display path.
  • Stable for the whole command body (including if (is-redirected)).

User-facing changes (Release notes)

Fixed is-terminal so it again reports whether process stdin/stdout/stderr is a real terminal (like bash test -t), including inside if (is-terminal). This restores correct detection for scripts such as ./script.nu | cat.

Added is-redirected for custom commands to detect whether their return value is piped, collected (let), written to a file, or discarded—versus printed for display. Unlike checking process stdout, this is stable for the whole command body and works inside if (is-redirected).

Example for pretty-vs-data commands:

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

mycmd            # pretty on a TTY when not piped
mycmd | $in      # data
let x = (mycmd)  # data

Scripts that only care about process stdout still use:

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

is-terminal with no flags still defaults to checking stdout.

A few other examples of how is-redirected is only designed to work on nushell destinations. These are all redirections with nushell destinations aka is-redirected = true.

• mycmd | $in / mycmd | where …
• let x = (mycmd)
• mycmd o> file
• mycmd | ignore

Additional notes

closes #15368

@fdncred
fdncred merged commit 0c601f7 into nushell:main Jul 18, 2026
14 checks passed
@fdncred
fdncred deleted the is_redirected_is_terminal_update branch July 18, 2026 21:35
fdncred pushed a commit that referenced this pull request Jul 18, 2026
<!--
Thanks for contributing to Nushell!

Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md

This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->

## Description
<!--
Explain what this PR does and why.

This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant

Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."

Write as much or as little as needed for reviewers to understand your
changes.
-->
This PR updates some tests of #18661 to make them more compact and use
more of our testing infra.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->
n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to determine if a output is being displayed in the terminal vs. piped to another command

1 participant