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

Completions #773

Merged
merged 3 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ rustls-backend = ["download/rustls-backend"]
# Include in the default set to disable self-update and uninstall.
no-self-update = []

# Used to change behavior of self-update and uninstall if installed via MSI
# Used to change behavior of self-update and uninstall if installed via MSI
msi-installed = []

[dependencies]
rustup-dist = { path = "src/rustup-dist", version = "0.6.4" }
rustup-utils = { path = "src/rustup-utils", version = "0.6.4" }
download = { path = "src/download" }
error-chain = "0.5.0"
clap = "2.11.3"
clap = "2.16.1"
regex = "0.1.41"
url = "1.1.0"
term = "0.4.4"
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,36 @@ you are ready to Rust. If you decide Rust isn't your thing, you can
completely remove it from your system by running `rustup self
uninstall`.

#### Enable tab completion for Zsh
#### Enable tab completion for Bash, Fish, or Zsh

Copy [`src/rustup-cli/zsh/_rustup`](https://github.com/rust-lang-nursery/rustup.rs/blob/master/src/rustup-cli/zsh/_rustup) into a directory, e.g. `~/.zfunc/`,
then add the following line in your `~/.zshrc` before `compinit`:
`rustup` now supports generating completion scripts for Bash, Fish,
and Zsh. See `rustup help completions` for full details, but the
gist is as simple as using one of the following:

```zsh
fpath+=~/.zfunc
```
# Bash
$ rustup completions bash > /etc/bash_completions.d/rustup.bash-completion

# Fish
$ rustup completions fish > ~/.config/fish/completions/rustup.fish

# Zsh
$ rustup completions zsh > ~/.zfunc/_rustup
```

*Note:* you may need to restart your shell in order for the changes to take affect.

#### Enable tab completion for Bash
*Note:* For Zsh, see additional details below

Waiting for [#278](https://github.com/rust-lang-nursery/rustup.rs/issues/278)
#### Addtional Notes for Zsh

One can alternatively copy [`src/rustup-cli/zsh/_rustup`](https://github.com/rust-lang-nursery/rustup.rs/blob/master/src/rustup-cli/zsh/_rustup) into a directory, e.g. `~/.zfunc/`.

Regardless of method, you must then add the following line in your `~/.zshrc` before `compinit`:

```zsh
fpath+=~/.zfunc
```

## How rustup works

Expand Down
68 changes: 68 additions & 0 deletions src/rustup-cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,71 @@ default browser.

By default, it opens the documentation index. Use the various flags to
open specific pieces of documentation.";

pub static COMPLETIONS_HELP: &'static str =
r"
One can generate a completion script for `rustup` that is compatible with
a given shell. The script is output on `stdout` allowing one to re-direct
the output to the file of their choosing. Where you place the file will
depend on which shell, and which operating system you are using. Your
particular configuration may also determine where these scripts need
to be placed.

Here are some common set ups for the three supported shells under
Unix and similar operating systems (such as GNU/Linux).

BASH:

Completion files are commonly stored in `/etc/bash_completion.d/`

Run the command:

`rustup completions bash > /etc/bash_completion.d/rustup.bash-completion`

This installs the completion script. You may have to log out and log
back in to your shell session for the changes to take affect.

FISH:

Fish completion files are commonly stored in
`$HOME/.config/fish/completions`

Run the command:
`rustup completions fish > ~/.config/fish/completions/rustup.fish`

This installs the completion script. You may have to log out and log
back in to your shell session for the changes to take affect.

ZSH:

ZSH completions are commonly stored in any directory listed in your
`$fpath` variable. To use these completions, you must either add the
generated script to one of those directories, or add your own
to this list.

Adding a custom directory is often the safest best if you're unsure
of which directory to use. First create the directory, for this
example we'll create a hidden directory inside our `$HOME` directory

`mkdir ~/.zfunc`

Then add the following lines to your `.zshrc` just before `compinit`

`fpath+=~/.zfunc`

Now you can install the completions script using the following command

`rustup completions zsh > ~/.zfunc/_rustup`

You must then either log out and log back in, or simply run

`exec zsh`

For the new completions to take affect.

CUSTOM LOCATIONS:

Alternatively, you could save these files to the place of your choosing,
such as a custom directory inside your $HOME. Doing so will require you
to add the proper directives, such as `source`ing inside your login
script. Consult your shells documentation for how to add such directives.";
15 changes: 13 additions & 2 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgGroup, AppSettings, SubCommand, ArgMatches};
use clap::{App, Arg, ArgGroup, AppSettings, SubCommand, ArgMatches, Shell};
use common;
use rustup::{Cfg, Toolchain, command};
use rustup::settings::TelemetryMode;
Expand All @@ -11,7 +11,7 @@ use std::path::Path;
use std::process::Command;
use std::iter;
use term2;
use std::io::Write;
use std::io::{self, Write};
use help::*;

pub fn main() -> Result<()> {
Expand Down Expand Up @@ -100,6 +100,11 @@ pub fn main() -> Result<()> {
(_, _) => unreachable!(),
}
}
("completions", Some(c)) => {
if let Some(shell) = c.value_of("shell") {
cli().gen_completions_to("rustup", shell.parse::<Shell>().unwrap(), &mut io::stdout());
}
}
(_, _) => unreachable!(),
}

Expand Down Expand Up @@ -343,6 +348,12 @@ pub fn cli() -> App<'static, 'static> {
.about("The triple used to identify toolchains when not specified")
.arg(Arg::with_name("host_triple")
.required(true))))
.subcommand(SubCommand::with_name("completions")
.about("Generate completion scripts for your shell")
.after_help(COMPLETIONS_HELP)
.setting(AppSettings::ArgRequiredElseHelp)
.arg(Arg::with_name("shell")
.possible_values(&["bash", "fish", "zsh"])))
}

fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches) -> Result<bool> {
Expand Down