Skip to content

Commit

Permalink
For cargo completion script, output line to source real script
Browse files Browse the repository at this point in the history
This allows the cargo script for the current default toolchain to be called,
and if the script is ever updated the user won't have to maually update their
completion script after updating Rust.

Signed-off-by: Gabriel Smith <[email protected]>
  • Loading branch information
yodaldevoid committed Feb 8, 2019
1 parent 7b2b26b commit 2eaafda
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,26 +1097,19 @@ fn output_completion_script(shell: Shell, command: CompletionCommand) -> Result<
cli().gen_completions_to("rustup", shell, &mut io::stdout());
}
CompletionCommand::Cargo => {
let prefix = "$(rustc --print sysroot)";
match shell {
Shell::Bash => {
writeln!(
&mut io::stdout(),
"{}{}",
prefix,
"/etc/bash_completion.d/cargo"
)?;
}
Shell::Zsh => {
writeln!(
&mut io::stdout(),
"{}{}",
prefix,
"/share/zsh/site-functions/_cargo"
)?;
}
_ => {}
let script = match shell {
Shell::Bash => Some("/etc/bash_completion.d/cargo"),
Shell::Zsh => Some("/share/zsh/site-functions/_cargo"),
_ => None,
};

if let Some(script) = script {
writeln!(
&mut io::stdout(),
"source $(rustc --print sysroot){}",
script,
)?;
}
}
}

Expand Down

0 comments on commit 2eaafda

Please sign in to comment.