Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make "modern" bash completion install recipes more dynamic
Browse files Browse the repository at this point in the history
The downside of installing completions in their expanded form is that
they should be re-installed on respective tool updates to keep them in
sync. Generating on demand fixes that, in exchange for a few
milliseconds on first load.
scop committed Nov 26, 2023
1 parent ece7d09 commit 65058ba
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/user-guide/src/installation/index.md
Original file line number Diff line number Diff line change
@@ -73,10 +73,10 @@ simple as using one of the following:

```console
# Bash
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
$ printf 'eval -- "$("$1" completions bash)"\n' > ~/.local/share/bash-completion/completions/rustup

# Bash (macOS/Homebrew)
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
$ printf 'eval -- "$(rustup completions bash)"\n' > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion

# Fish
$ mkdir -p ~/.config/fish/completions
13 changes: 8 additions & 5 deletions src/cli/help.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ pub(crate) static DOC_HELP: &str = r"Discussion:
By default, it opens the documentation index. Use the various
flags to open specific pieces of documentation.";

pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
pub(crate) static COMPLETIONS_HELP: &str = r#"Discussion:
Enable tab completion for Bash, Fish, Zsh, or PowerShell
The script is output on `stdout`, allowing one to re-direct the
output to the file of their choosing. Where you place the file
@@ -175,7 +175,8 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
Run the command:
$ mkdir -p ~/.local/share/bash-completion/completions
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
$ printf 'eval -- "$("$1" completions bash)"\n' \
> ~/.local/share/bash-completion/completions/rustup
This installs the completion script. You may have to log out and
log back in to your shell session for the changes to take effect.
@@ -186,7 +187,8 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
With the `bash-completion` brew formula installed, run the command:
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
$ printf 'eval -- "$(rustup completions bash)"\n' \
> $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
Fish:
@@ -270,11 +272,12 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
Bash:
$ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo
$ printf 'eval -- "$(rustup completions bash cargo)"\n' \
> ~/.local/share/bash-completion/completions/cargo
Zsh:
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
$ rustup completions zsh cargo > ~/.zfunc/_cargo"#;

pub(crate) static OFFICIAL_TOOLCHAIN_ARG_HELP: &str =
"Toolchain name, such as 'stable', 'nightly', \
Original file line number Diff line number Diff line change
@@ -32,7 +32,8 @@ Discussion:
Run the command:
$ mkdir -p ~/.local/share/bash-completion/completions
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
$ printf 'eval -- "$("$1" completions bash)"\\n' \\
> ~/.local/share/bash-completion/completions/rustup
This installs the completion script. You may have to log out and
log back in to your shell session for the changes to take effect.
@@ -43,7 +44,8 @@ Discussion:
With the `bash-completion` brew formula installed, run the command:
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
$ printf 'eval -- "$(rustup completions bash)"\\n' \\
> $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
Fish:
@@ -128,7 +130,8 @@ Discussion:
Bash:
$ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo
$ printf 'eval -- "$(rustup completions bash cargo)"\\n' \\
> ~/.local/share/bash-completion/completions/cargo
Zsh:

0 comments on commit 65058ba

Please sign in to comment.