From 129f159d43d8fdcf346d6567a07bf838b7879058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 22 Jan 2023 13:18:53 +0200 Subject: [PATCH] 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. A caveat is that the use of `<( ... )` requires the shell to be in non-POSIX mode. In my opinion, POSIX mode interactive bash is too rare a creature to pass on this recipe improvement. --- doc/user-guide/src/installation/index.md | 4 ++-- src/cli/help.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/user-guide/src/installation/index.md b/doc/user-guide/src/installation/index.md index d97dd3f7b04..2e2a53dd3bb 100644 --- a/doc/user-guide/src/installation/index.md +++ b/doc/user-guide/src/installation/index.md @@ -73,10 +73,10 @@ simple as using one of the following: ```console # Bash -$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup +$ printf '. <(rustup 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 '. <(rustup completions bash)\n' > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion # Fish $ mkdir -p ~/.config/fish/completions diff --git a/src/cli/help.rs b/src/cli/help.rs index cfade1afb72..37c3e52371d 100644 --- a/src/cli/help.rs +++ b/src/cli/help.rs @@ -175,7 +175,7 @@ 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 '. <(rustup 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 +186,7 @@ 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 '. <(rustup completions bash)\n' > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion Fish: @@ -270,7 +270,7 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion: Bash: - $ rustup completions bash cargo > ~/.local/share/bash-completion/completions/cargo + $ printf '. <(rustup completions bash cargo)\n' > ~/.local/share/bash-completion/completions/cargo Zsh: