npx icon indicating copy to clipboard operation
npx copied to clipboard

shell tab-completion

Open zkat opened this issue 7 years ago • 13 comments

jfc please just give us completion support, at least for existing binaries in the $PATH or in ~/.npm/_npx/bin. There's gotta be something nice and easy the cool kids use these days to set up easy completion stuff.

Do you wanna pick this up? I'd love the help.

zkat avatar May 30 '17 08:05 zkat

@zkat Do you mean using auto completion functionality for shells like Bash or Zsh ? :))

pi0 avatar May 30 '17 09:05 pi0

@pi0 I want to do npx stan<TAB> -> npx standard, if standard is in the $PATH. It's not really necessary to auto-complete for remote package names (yet?), but having the basic thing working would be nice.

zkat avatar May 30 '17 09:05 zkat

I got it running on a few shells:

  • For bash, it requires adding complete -A command npx to your ~/.bashrc file.
  • For zsh, it requires adding compctl -m npx to your ~/.zshrc file.

Issue with this command though is that it returns all the commands in $PATH, not just those installed with npm. I didn't get it running on fish, but if there are some enthusiasts here, there's a complete function in fish - that has a man page.

Also, it's possible for bash and zsh to program the shell to call a shell function to get the completion list - so depending on the shell, it could be possible for users to auto-complete for remote package names.

What do you think should be the approach to let users know about this, add it in the README?

egourlao avatar May 31 '17 19:05 egourlao

@dotpy3 I think having something for folks to get started is a great idea. We can deal with remote-pkg autocompletion later, since that is a little harder (the search space is enormous and I need to see what the state-of-the-art is for the registry rn)

I would add a section to the README that describes how to set up auto completion.

zkat avatar May 31 '17 21:05 zkat

I want to do npx stan<TAB> -> npx standard, if standard is in the ./node_modules/.bin/ but not in the $PATH.

We need a shell plugin like this one -> robbyrussell/oh-my-zsh#1614 .

LitoMore avatar Jul 16 '17 09:07 LitoMore

I can start the completions for fish.

kaleb avatar Jul 28 '17 15:07 kaleb

@kaleb awesome!

zkat avatar Jul 28 '17 18:07 zkat

When we get there later, there's an Algolia index with all package information that could be used, this should be fast enough for auto-completion. I can provide more information if wanted

Haroenv avatar Aug 07 '17 08:08 Haroenv

I've made a bash script that might put some light on the matter: https://gist.github.com/gibatronic/44073260ffdcbd122e9520756c8e35a1

When typing npx <tab> it is going to suggest any executable inside the ./node_modules/.bin/ folder.

gibatronic avatar Feb 18 '18 22:02 gibatronic

Any updates about the remote search or the actual completion script 😃? I just though about doing this 😅

@Haroenv can you please provide more info about that Algolia index? 😊

alvaropinot avatar May 11 '18 00:05 alvaropinot

All info for that should be at https://github.com/Algolia/npm-search, an example usage is https://github.com/yarnpkg/website or Emma CLI. Feel free to ask more info in email ([email protected])

Haroenv avatar May 11 '18 06:05 Haroenv

We don't use Algolia and we won't be. We have our own completion endpoint but it needs to be scaled/load-tested before it can be made public (and thus the CLI can use it). We actually don't like Algolia's results very much (and yes, I'm leaving it at that).

zkat avatar May 11 '18 16:05 zkat

Sure, sorry for suggesting :)

Haroenv avatar May 11 '18 16:05 Haroenv