Skip to content

Commit 65058ba

Browse files
committed
Make "modern" bash completion install recipes more dynamic
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.
1 parent ece7d09 commit 65058ba

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

doc/user-guide/src/installation/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ simple as using one of the following:
7373

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

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

8181
# Fish
8282
$ mkdir -p ~/.config/fish/completions

src/cli/help.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub(crate) static DOC_HELP: &str = r"Discussion:
156156
By default, it opens the documentation index. Use the various
157157
flags to open specific pieces of documentation.";
158158

159-
pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
159+
pub(crate) static COMPLETIONS_HELP: &str = r#"Discussion:
160160
Enable tab completion for Bash, Fish, Zsh, or PowerShell
161161
The script is output on `stdout`, allowing one to re-direct the
162162
output to the file of their choosing. Where you place the file
@@ -175,7 +175,8 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
175175
Run the command:
176176
177177
$ mkdir -p ~/.local/share/bash-completion/completions
178-
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
178+
$ printf 'eval -- "$("$1" completions bash)"\n' \
179+
> ~/.local/share/bash-completion/completions/rustup
179180
180181
This installs the completion script. You may have to log out and
181182
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:
186187
With the `bash-completion` brew formula installed, run the command:
187188
188189
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
189-
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
190+
$ printf 'eval -- "$(rustup completions bash)"\n' \
191+
> $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
190192
191193
Fish:
192194
@@ -270,11 +272,12 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
270272
271273
Bash:
272274
273-
$ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo
275+
$ printf 'eval -- "$(rustup completions bash cargo)"\n' \
276+
> ~/.local/share/bash-completion/completions/cargo
274277
275278
Zsh:
276279
277-
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
280+
$ rustup completions zsh cargo > ~/.zfunc/_cargo"#;
278281

279282
pub(crate) static OFFICIAL_TOOLCHAIN_ARG_HELP: &str =
280283
"Toolchain name, such as 'stable', 'nightly', \

tests/suite/cli-ui/rustup/rustup_completions_cmd_help_flag_stdout.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Discussion:
3232
Run the command:
3333
3434
$ mkdir -p ~/.local/share/bash-completion/completions
35-
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
35+
$ printf 'eval -- "$("$1" completions bash)"\\n' \\
36+
> ~/.local/share/bash-completion/completions/rustup
3637
3738
This installs the completion script. You may have to log out and
3839
log back in to your shell session for the changes to take effect.
@@ -43,7 +44,8 @@ Discussion:
4344
With the `bash-completion` brew formula installed, run the command:
4445
4546
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
46-
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
47+
$ printf 'eval -- "$(rustup completions bash)"\\n' \\
48+
> $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
4749
4850
Fish:
4951
@@ -128,7 +130,8 @@ Discussion:
128130
129131
Bash:
130132
131-
$ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo
133+
$ printf 'eval -- "$(rustup completions bash cargo)"\\n' \\
134+
> ~/.local/share/bash-completion/completions/cargo
132135
133136
Zsh:
134137

0 commit comments

Comments
 (0)