Open
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
- Run
ls file.txt | get name | vi ...$in
- The following error is printed:
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
- Vim crashes.
mg
- Run
ls file.txt | get name | mg ...$in
- The error "panic: standard input and output must be a terminal" is printed
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 |