-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bash completion install doc improvements #3177
base: master
Are you sure you want to change the base?
Conversation
I've never looked particularly closely at completions. What does bash do to avoid running that command on every completion request? |
https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html has the background details. There's no anchor to link to on that page, but search for "There is some support for dynamically modifying completions" towards the end of it. More specifically for this particular case, the https://github.com/scop/bash-completion project that I co-maintain is "in charge" of loading completions dynamically from the mentioned |
ccd0f0e
to
129f159
Compare
Rebased/resolved conflicts. |
129f159
to
1892727
Compare
…etions /etc/bash_completion.d works too, but the downside is that everything there is loaded eagerly at bash_completion load time, slowing down shell startup. From /usr/share/bash-completion/completions completion files are loaded on demand. This mechanism is available as of bash-completion version 2 and later, just like the ~/.local/share/bash-completion/completions one that is already suggested for user-specific completions.
It's not that much about whether a command is system-wide or user-specific, but more about whether the completion is. In particular, the user-specific completions file dir is used to override system-wide completion, or to add completion for a command that does not have a system-wide completion installed. This is orthogonal to whether the command is installed system-wide or user-specific.
There should be no reason to append to existing ones. Other similar completion file install recipes overwrite, too.
67c319e
to
ac48ae1
Compare
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.
ac48ae1
to
65058ba
Compare
Updated, but no success yet: something seems to be changing backslash escapes to slashes in the outputs, don't know what should be done about that. |
@scop Sorry for the late reply! I'll paste the original error below for the sake of convenience: ---- expected: stdout
++++ actual: stdout
1 1 | ...
2 2 | Generate tab-completion scripts for your shell
3 3 |
4 4 | Usage: rustup[EXE] completions [shell] [command]
5 5 |
⋮
27 27 | `/usr/share/bash-completion/completions`, and user-specific ones
28 28 | can be stored in `~/.local/share/bash-completion/completions`.
29 29 | Run the command:
30 30 |
31 31 | $ mkdir -p ~/.local/share/bash-completion/completions
32 - $ printf 'eval -- "$("$1" completions bash)"\n' \
32 + $ printf 'eval -- "$("$1" completions bash)"/n' /
33 33 | > ~/.local/share/bash-completion/completions/rustup
34 34 |
35 35 | This installs the completion script. You may have to log out and
36 36 | log back in to your shell session for the changes to take effect.
37 37 |
⋮
39 39 |
40 40 | Homebrew stores bash completion files within the Homebrew directory.
41 41 | With the `bash-completion` brew formula installed, run the command:
42 42 |
43 43 | $ mkdir -p $(brew --prefix)/etc/bash_completion.d
44 - $ printf 'eval -- "$(rustup completions bash)"\n' \
44 + $ printf 'eval -- "$(rustup completions bash)"/n' /
45 45 | > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
46 46 |
47 47 | Fish:
48 48 |
49 49 | Fish completion files are commonly stored in
⋮
125 125 | toolchain. Not all shells are currently supported. Here are examples for
126 126 | the currently supported shells.
127 127 |
128 128 | Bash:
129 129 |
130 - $ printf 'eval -- "$(rustup completions bash cargo)"\n' \
130 + $ printf 'eval -- "$(rustup completions bash cargo)"/n' /
131 131 | > ~/.local/share/bash-completion/completions/cargo
132 132 |
133 133 | Zsh:
134 134 |
135 135 | $ rustup completions zsh cargo > ~/.zfunc/_cargo
(cc @epage) Update: As it turns out, the replacement of |
|
@epage Thanks for your quick response! This seems to be assert-rs/snapbox#91 then. |
Seems fine? |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the value of using $1
here? It seems rather obfuscated to me.
See individual commits for details.