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

tab completions #278

Closed
brson opened this issue Apr 6, 2016 · 14 comments
Closed

tab completions #278

brson opened this issue Apr 6, 2016 · 14 comments

Comments

@brson
Copy link
Contributor

brson commented Apr 6, 2016

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.

@japaric
Copy link
Member

japaric commented Apr 15, 2016

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 😄. I would be happy if rustup just installs a _rustup completion file somewhere in the .multirust folder like it does with _cargo.

@kbknapp
Copy link
Contributor

kbknapp commented Jul 2, 2016

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

@Diggsey
Copy link
Contributor

Diggsey commented Jul 2, 2016

@kbknapp Wow, that's awesome!

@wuranbo
Copy link

wuranbo commented Jul 2, 2016

go go go

@brson
Copy link
Contributor Author

brson commented Jul 5, 2016

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

@knight42
Copy link
Contributor

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

@kbknapp
Copy link
Contributor

kbknapp commented Aug 26, 2016

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

@knight42
Copy link
Contributor

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

kbknapp added a commit to kbknapp/multirust-rs that referenced this issue Oct 24, 2016
This commit adds two sections to the command line options to enable building of Shell Completion
Scripts to `stdout`. This allows these scripts to be redirected to a file, effectively allowing
the user to install these scripts at the location of their choosing.

The arguments only accept the values `zsh`, `fish` and `bash`, which clap guards against.

To use these scripts one must do one of the following

*Note:* The commands `rustup completions <SHELL>` and `rustup self --completions <SHELL>` are
synonyms for each other, and do the exact same thing.

```
$ rustup completions bash > /path/to/completions/dir/rustup.bash-completion
```

```
$ rustup completions fish > ~/.config/fish/completions/rustup.fish
```

```
$ mkdir ~/.zfunc
$ rustup completions zsh > ~/.zfunc/_rustup
$ echo "fpath+=~/.zfunc\ncominit" >> ~/.zshrc
$ exec zsh
```

Relates to rust-lang#278
@kbknapp
Copy link
Contributor

kbknapp commented Oct 24, 2016

@knight42

I've just added ZSH support to clap (finally! 🎉), 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

@knight42
Copy link
Contributor

@kbknapp Awesome, love it!

kbknapp added a commit to kbknapp/multirust-rs that referenced this issue Oct 24, 2016
This commit adds two sections to the command line options to enable building of Shell Completion
Scripts to `stdout`. This allows these scripts to be redirected to a file, effectively allowing
the user to install these scripts at the location of their choosing.

The arguments only accept the values `zsh`, `fish` and `bash`, which clap guards against.

To use these scripts one must do one of the following

*Note:* The commands `rustup completions <SHELL>` and `rustup self --completions <SHELL>` are
synonyms for each other, and do the exact same thing.

```
$ rustup completions bash > /path/to/completions/dir/rustup.bash-completion
```

```
$ rustup completions fish > ~/.config/fish/completions/rustup.fish
```

```
$ mkdir ~/.zfunc
$ rustup completions zsh > ~/.zfunc/_rustup
$ echo "fpath+=~/.zfunc\ncominit" >> ~/.zshrc
$ exec zsh
```

Relates to rust-lang#278
@est31
Copy link
Member

est31 commented Oct 26, 2016

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.

@kbknapp
Copy link
Contributor

kbknapp commented Oct 26, 2016

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

@kbknapp
Copy link
Contributor

kbknapp commented Oct 26, 2016

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

nodakai pushed a commit to nodakai/rustup.rs that referenced this issue Apr 23, 2017
This commit adds two sections to the command line options to enable building of Shell Completion
Scripts to `stdout`. This allows these scripts to be redirected to a file, effectively allowing
the user to install these scripts at the location of their choosing.

The arguments only accept the values `zsh`, `fish` and `bash`, which clap guards against.

To use these scripts one must do one of the following

*Note:* The commands `rustup completions <SHELL>` and `rustup self --completions <SHELL>` are
synonyms for each other, and do the exact same thing.

```
$ rustup completions bash > /path/to/completions/dir/rustup.bash-completion
```

```
$ rustup completions fish > ~/.config/fish/completions/rustup.fish
```

```
$ mkdir ~/.zfunc
$ rustup completions zsh > ~/.zfunc/_rustup
$ echo "fpath+=~/.zfunc\ncominit" >> ~/.zshrc
$ exec zsh
```

Relates to rust-lang#278
@Diggsey
Copy link
Contributor

Diggsey commented May 4, 2017

I think this can be considered complete?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants