Rustup: tab completions

Created on 6 Apr 2016  路  14Comments  路  Source: rust-lang/rustup

I've been using it for almost a week and seems great! I only miss tab completions, that would be awesome :slight_smile: thanks Brian!

Hm, after thinking about this further, tab completions are going to be tricky. rustup does not require root to install but completions are usually installed to /etc. I really don't want to require admin just for that. I wonder if we might further frob the shell startup files (like we already to to modify PATH) to load completions.

Source.

Most helpful comment

@brson @japaric

I've just added the ability to generate bash completions for a cli with clap at compile time. Here's a gist of the generated completion script for rustup

And a demo:

rustup_compl

I have a branch on my fork where I generated the completions, although before I'd put in a PR there are few opinionated portions that I'd rather a project maintainer look at prior

  • having to move the rustup_mode::cli function into a separate file in order to include via the build.rs.
  • there's a strange issue where I couldn't use help::*; from rustup_app.rs so I had to include! it.
  • finally, the output of the completion script goes to OUT_DIR

Granted this is only a Bash completion script, but it's at least a step in _a_ direction (if it's the _right_ direction is TBD). I personally use ZSH, so that's next on my list.

All 14 comments

I wonder if we might further frob the shell startup files (like we already to to modify PATH) to load completions.

FWIW, in my case I use zsh and I enable the cargo auto completions (that rustup installs) without touching the /etc directory by modifying the fpath variable in my zshrc as shown here. I also use the oh-my-zsh framework and I've noticed that I need to modify the fpath variable before sourcing the oh-my-zsh framework.

Disclaimer: I don't really grok zsh internals and perhaps there is a way to enable cargo autocompletions after the oh-my-zsh framework has been loaded.

P.S. I don't really like that CLI tools modify my zshrc, I usually undo/modify what they do :smile:. I would be happy if rustup just installs a _rustup completion file somewhere in the .multirust folder like it does with _cargo.

@brson @japaric

I've just added the ability to generate bash completions for a cli with clap at compile time. Here's a gist of the generated completion script for rustup

And a demo:

rustup_compl

I have a branch on my fork where I generated the completions, although before I'd put in a PR there are few opinionated portions that I'd rather a project maintainer look at prior

  • having to move the rustup_mode::cli function into a separate file in order to include via the build.rs.
  • there's a strange issue where I couldn't use help::*; from rustup_app.rs so I had to include! it.
  • finally, the output of the completion script goes to OUT_DIR

Granted this is only a Bash completion script, but it's at least a step in _a_ direction (if it's the _right_ direction is TBD). I personally use ZSH, so that's next on my list.

@kbknapp Wow, that's awesome!

go go go

@kbknapp Sweet! That's really clever.

I'm fine doing the conversion, but I'd still like to wait until we understand how to install them before pulling trigger.

@kbknapp Any progress now? It's a pain to me when auto-completion is unable to use.

@knight42 I haven't added ZSH support yet. Once I do I'll post back here.

@kbknapp Great! It's better to generate the completion script automatically. I am looking forward to it!

@knight42

I've just added ZSH support to clap (finally! :tada:), and put in a PR to rustup to add it. The PR also includes Bash, and Fish support as well.

Here's a gif of the ZSH support though:

rustup_zsh

@kbknapp Awesome, love it!

Thanks for the autocompletion feature @kbknapp I really like it!

Would it be possible to extend the tab completion support to include things rustup can derive? Like when you type rustup override add<TAB><TAB> it should give you a list of toolchains.

Its obviously more complicated, but should be doable, no?

flatpak manages to do this btw, you can press flatpak run org.app.<TAB> and it will autocomplete the app name.

@est31 not yet, but that is the exact topic of kbknapp/clap-rs#568

I should add you can do this manually, but it's not built in to clap yet :will:

I think this can be considered complete?

Was this page helpful?
0 / 5 - 0 ratings