Skip to content

Commit 1892727

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 0329355 commit 1892727

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Diff for: 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

Diff for: src/cli/help.rs

+5-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,7 @@ 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' > ~/.local/share/bash-completion/completions/rustup
179179
180180
This installs the completion script. You may have to log out and
181181
log back in to your shell session for the changes to take effect.
@@ -186,7 +186,7 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
186186
With the `bash-completion` brew formula installed, run the command:
187187
188188
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
189-
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
189+
$ printf 'eval -- "$(rustup completions bash)"\n' > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
190190
191191
Fish:
192192
@@ -270,11 +270,11 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
270270
271271
Bash:
272272
273-
$ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo
273+
$ printf 'eval -- "$(rustup completions bash cargo)"\n' > ~/.local/share/bash-completion/completions/cargo
274274
275275
Zsh:
276276
277-
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
277+
$ rustup completions zsh cargo > ~/.zfunc/_cargo"#;
278278

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

Diff for: tests/suite/cli-ui/rustup/rustup_completions_cmd_help_flag_stdout.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ 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' > ~/.local/share/bash-completion/completions/rustup
3636
3737
This installs the completion script. You may have to log out and
3838
log back in to your shell session for the changes to take effect.
@@ -43,7 +43,7 @@ Discussion:
4343
With the `bash-completion` brew formula installed, run the command:
4444
4545
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
46-
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
46+
$ printf 'eval -- "$(rustup completions bash)"\n' > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
4747
4848
Fish:
4949
@@ -128,7 +128,7 @@ Discussion:
128128
129129
Bash:
130130
131-
$ rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo
131+
$ printf 'eval -- "$(rustup completions bash cargo)"\n' > ~/.local/share/bash-completion/completions/cargo
132132
133133
Zsh:
134134

0 commit comments

Comments
 (0)