Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The complete command doesn't work with interactive commands #8539

Closed
stevenxxiu opened this issue Mar 20, 2023 · 11 comments
Closed

The complete command doesn't work with interactive commands #8539

stevenxxiu opened this issue Mar 20, 2023 · 11 comments
Labels
external-commands Issues related to external commands redirection-pipe All related to redirection to files or more complex pipelines with STDERR streaming Issues related to streaming data (or collecting data when it should be streamed)

Comments

@stevenxxiu
Copy link
Contributor

Describe the bug

complete doesn't wait until interactive command finishes.

It shows nothing at first. After pressing Ctrl + C, the interactive command's output shows up.

In the test case below, the goal is to capture stderr of the command, via do { atuin search --interactive } | complete.

How to reproduce

Run atuin search --interactive | complete.

Expected behavior

I expect complete to wait until the interactive command finishes.

Screenshots

No response

Configuration

key value
version 0.77.2
branch makepkg
commit_hash 2d41613
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.68.0 (2c8cc3432 2023-03-06) (Arch Linux rust 1:1.68.0-1)
cargo_version cargo 1.68.0
build_time 2023-03-18 00:10:14 +00:00
build_rust_channel release
features default, zip
installed_plugins

Additional context

No response

@sophiajt
Copy link
Contributor

Does do -i { atuin search --interactive } | complete work? do by default doesn't redirect stderr

@stevenxxiu
Copy link
Contributor Author

Nope this has the same behavior as described above. No output shows at first, then once Ctrl + C is pressed, the interactive output shows up.

@sophiajt
Copy link
Contributor

Makes me wonder if it doesn't want stdout redirected?

vim and similar editors have this behaviour. If so, we'd have to redirect only stderr and not stdout.

@stevenxxiu
Copy link
Contributor Author

Makes me wonder if it doesn't want stdout redirected?

Yup that's the issue here.

@sholderbach sholderbach added external-commands Issues related to external commands streaming Issues related to streaming data (or collecting data when it should be streamed) redirection-pipe All related to redirection to files or more complex pipelines with STDERR labels Mar 20, 2023
@stevenxxiu
Copy link
Contributor Author

@sophiajt
Copy link
Contributor

I tried this on the latest main, and this variation seems to work for me: run-external --redirect-stderr atuin search "--interactive" | complete | $in.stderr

@sophiajt
Copy link
Contributor

The reason the original one isn't working is because complete is getting, by default, stdout rather than stderr. So you need to go through the helper command to turn off the stdout and turn on the stderr.

@stevenxxiu
Copy link
Contributor Author

Thanks, that works indeed. I suppose for complete to work with interactive commands I can just use run-external.

@fdncred
Copy link
Collaborator

fdncred commented Mar 28, 2023

Seems like we need to document the reason for why/how run-external works. Maybe on the bash to nushell page? It's a little odd.

On the other hand, this bash syntax is A LOT odd -i -- "$0" 3>&1 1>&2 2>&3' (commandline)) 🤣

@zhiburt
Copy link
Contributor

zhiburt commented Mar 30, 2023

Hi there;

Just a note that run-external works only with binaries but not builtin commands;

~/bin/nushell> run-external --redirect-stderr inspect                                                                          03/31/2023 02:22:15 AM
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #22:1:1]
 1 │ run-external --redirect-stderr inspect
   ·                                ───┬───
   ·                                   ╰── did you mean 'inspect'?
   ╰────
  help: No such file or directory (os error 2)

@fdncred
Copy link
Collaborator

fdncred commented Mar 30, 2023

Related to this issue and with atuin, we found out this worked run-external --redirect-stderr atuin search "--interactive" | complete | $in.stderr.

Good point @zhiburt. run-external is not meant for internal commands. The error message could be more helpful though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-commands Issues related to external commands redirection-pipe All related to redirection to files or more complex pipelines with STDERR streaming Issues related to streaming data (or collecting data when it should be streamed)
Projects
None yet
Development

No branches or pull requests

5 participants