Skip to content

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

Closed

Description

@stevenxxiu

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

Activity

  1. sophiajt commented on Mar 20, 2023

    @sophiajt
    Contributor

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

  2. stevenxxiu commented on Mar 20, 2023

    @stevenxxiu
    ContributorAuthor

    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.

  3. sophiajt commented on Mar 20, 2023

    @sophiajt
    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.

  4. stevenxxiu commented on Mar 20, 2023

    @stevenxxiu
    ContributorAuthor

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

    Yup that's the issue here.

  5. added
    A:external-commands
    A:streaming
    A:redirection-pipe
    on Mar 20, 2023
  6. stevenxxiu commented on Mar 21, 2023

    @stevenxxiu
    ContributorAuthor
  7. sophiajt commented on Mar 27, 2023

    @sophiajt
    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

  8. sophiajt commented on Mar 28, 2023

    @sophiajt
    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.

  9. stevenxxiu commented on Mar 28, 2023

    @stevenxxiu
    ContributorAuthor

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

  10. fdncred commented on Mar 28, 2023

    @fdncred
    Contributor

    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)) 🤣

  11. zhiburt commented on Mar 30, 2023

    @zhiburt
    Contributor

    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)
  12. fdncred commented on Mar 30, 2023

    @fdncred
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:external-commandsA:redirection-pipeA:streaming

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions