rye icon indicating copy to clipboard operation
rye copied to clipboard

Tab completion: `rye run x` should yield completion to the called executable

Open whi-tw opened this issue 1 year ago • 8 comments

Steps to Reproduce

  1. rye run pyt <tab>

  2. rye run -- pyt <tab>

Expected Result

I'd expect to see the completions of the called command

Actual Result

No completions, bell sounds

Version Info

rye 0.2.0 commit: 0.2.0 (d87583862 2023-05-23) platform: macos (aarch64) self-python: [email protected] symlink support: true

Stacktrace

No response

whi-tw avatar May 24 '23 13:05 whi-tw

This has been achieved nicely in 99designs/aws-vault for bash,zsh and fish.

Their implementation uses a switch on -- - all completion after that sequence is handed off back to the shell's concept of _normal (ie. as if you triggered completion with an empty prompt line)

whi-tw avatar May 24 '23 13:05 whi-tw

I'm not sure exactly what the ask is here. You can already generate a completion script. Is the ask to automatically install these?

rye self completion -s zsh

mitsuhiko avatar May 24 '23 15:05 mitsuhiko

No, sorry, not that.

The ask is that rye run -- py<tab> would return the same completion options as if you just typed py<tab> on the cli.

This would mean you could use tab completion for commands which are run using rye run, rather than them just being swallowed up as no-ops by _rye.

whi-tw avatar May 24 '23 15:05 whi-tw

Not sure if it's possible to actually do this without generating out a really complex script. The issue is that the completion would actually depend on what's configured in the scripts or what can be found. It's not invoking directly a script on PATH.

mitsuhiko avatar May 24 '23 15:05 mitsuhiko

I've written a number of CLI apps which do this, using the patterns in the scripts I linked here: https://github.com/mitsuhiko/rye/issues/213#issuecomment-1561176097 - do you not think those would work in the case of rye?

I'm not super au-fait with rust, but I might have a go and see if I can get something working

whi-tw avatar May 24 '23 15:05 whi-tw

The issue here is not Rust, but that the command after rye run is not on the PATH. So how would the shell know what to expand?

mitsuhiko avatar May 24 '23 15:05 mitsuhiko

oooh, valid point 🤦🏻‍♂️ I had my head in "general-task-runner" mode, not "we're running commands in a very specific environment" mode.

completely misread this:

The issue is that the completion would actually depend on what's configured in the scripts or what can be found

whi-tw avatar May 24 '23 15:05 whi-tw

I think if this ever gets fixed it might be possible to do something: https://github.com/clap-rs/clap/issues/1232

mitsuhiko avatar May 24 '23 15:05 mitsuhiko

Closing this for now as I do not believe work here will actually take place.

mitsuhiko avatar Jan 20 '24 19:01 mitsuhiko

I'm asking this here since it's related. I'm not a shell expert but here is what I know from observation; when shells can't provide completion then the suggestions are files/directories in the current working directory. For some reason, rye run pytest [tab] is not doing that.

In poetry and pdm and most tools I'm able to select a file or directory.

Usage: I usually run tests found in a specific directory and it would be nice if I can get completion working to make a selection quickly.

abdulhaq-e avatar Mar 05 '24 16:03 abdulhaq-e

I agree with @abdulhaq-e . At the moment rye seems to consume any tab event, but it would be nice to do rye run foo /path/to/<tab> and have it autocomplete whatever is in that directory. Should this be a new issue?

hgaiser avatar May 23 '24 12:05 hgaiser