Skip to content

Text editors cannot open $in when spread #14884

Open
@RolandMarchand

Description

Describe the bug

Interactive applications such as text editors are not able to open files when spreading $in, such as ls file.txt | get name | vi ...$in.

How to reproduce

All these cases assume file.txt exists.

Vim

  1. Run ls file.txt | get name | vi ...$in
  2. The following error is printed:
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
  1. Vim crashes.

mg

  1. Run ls file.txt | get name | mg ...$in
  2. The error "panic: standard input and output must be a terminal" is printed
  3. mg crashes.

In the case of mg, the code panics at ttyio.c:ttopen() after failed isatty(3) calls:

/*
 * This function gets called once, to set up the terminal.
 * On systems w/o TCSASOFT we turn off off flow control,
 * which isn't really the right thing to do.
 */
void
ttopen(void)
{
	if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
		panic("standard input and output must be a terminal"); // here

	if (ttraw() == FALSE)
		panic("aborting due to terminal initialize failure");
}

Expected behavior

In Nushell, ls file.txt | get name | mg ...$in should:

  • ✅ be equivalent to realpath file.txt | xargs -o mg in Bash
  • ❌ not be equivalent to realpath file.txt | xargs mg in Bash

This is a known issue with xargs; it points stdin to /dev/null while Vim expects its stdin to be the same as its controlling terminal. This issue can be mitigated by using xargs -o instead:

Reopen stdin as /dev/tty in the child process before executing the command. This is useful if you want xargs to run an interactive application.

This use case should also be updated in the documentation.

Configuration

key value
version 0.99.1
major 0
minor 99
patch 1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.82.0 (f6e511eec 2024-10-15) (Fedora 1.82.0-1.fc41)
cargo_version cargo 1.82.0 (8f40fc59f 2024-08-21)
build_time 2024-11-20 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins

Metadata

Assignees

No one assigned

    Labels

    documentationissues relating to documentationredirection-pipeAll related to redirection to files or more complex pipelines with STDERRsemanticsPlaces where we should define/clarify nushell's semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions