Repository navigation
Allow is-terminal to detect redirection - #18443
Merged
fdncred merged 1 commit intoJun 22, 2026
Merged
Conversation
fdncred
added a commit
that referenced
this pull request
Jul 18, 2026
…estinations (#18661) ## 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 #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: ```nushell 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: ```nushell 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`. ```nushell • mycmd | $in / mycmd | where … • let x = (mycmd) • mycmd o> file • mycmd | ignore ``` ## Additional notes closes #15368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR enables the
is-terminalcommand to detect redirection. The command without any flags defaults to--stdout.User-facing changes (Release notes)
The
is-terminalcommand can detect redirection now. It now defaults to--stdout.Additional notes
closes #15368