Skip to content

Commit 8bc5297

Browse files
authored
docs: update Linux bash completion setup docs (#369)
In many setups, with bash-completion >= 2.12 installed, nothing needs to be done these days.
1 parent beebccd commit 8bc5297

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

docs/index.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,38 @@ On bash, the completions depend on `bash-completion` package. Install and config
122122

123123
=== "Linux"
124124

125-
First, install `bash-completion` package, if it has not been installed already, and add command to source the completions to your `.bashrc`.
125+
First, install `bash-completion` package, if it has not been installed already.
126126

127127
On Ubuntu or Debian, use `apt` command to install the package:
128128

129129
```sh
130130
sudo apt install bash-completion
131-
echo "[ -f /etc/bash_completion ] && . /etc/bash_completion" >> ~/.bashrc
132131
```
133132

134-
On RHEL based distributions, use `dnf` command to install the package.
133+
On RHEL and Fedora based distributions, use `dnf` command to install the package.
135134

136135
```sh
137136
sudo dnf install bash-completion
138-
echo "[ -f /etc/bash_completion ] && . /etc/bash_completion" >> ~/.bashrc
139137
```
140138

141-
Finally, configure the shell completions for `upctl` by either sourcing `upctl completion bash` output in your bash `.bashrc` or by saving the output of that command in `upctl` file under `/etc/bash_completion.d/`:
139+
Most distributions' packages enable bash-completion automatically.
140+
If not, something like this can be done to accomplish that:
142141

143142
```sh
144-
# First alternative
145-
echo 'source <(upctl completion bash)' >>~/.bashrc
143+
printf "%s\n" "[[ -f /usr/share/bash-completion/bash-completion ]] && . /usr/share/bash-completion/bash-completion" >> ~/.bashrc
144+
```
145+
146+
If your bash-completion version is 2.12 or newer, no further steps are needed,
147+
upctl completion will load automatically on demand. With older bash-completion versions,
148+
the autoloading needs to be set up. Something like this will accomplish that:
146149

147-
# Second alternative
148-
upctl completion bash | sudo tee /etc/bash_completion.d/upctl > /dev/null
150+
```sh
151+
# Either system wide:
152+
printf "%s\n" 'eval -- "$("$1" completion bash 2>/dev/null)"' > /usr/share/bash-completion/completions/upctl
149153

150-
# Source completions to current shell session
151-
. /etc/bash_completion
154+
# ...or per user:
155+
mkdir -p ~/.local/share/bash-completion/completions
156+
printf "%s\n" 'eval -- "$("$1" completion bash 2>/dev/null)"' > ~/.local/share/bash-completion/completions/upctl
152157
```
153158

154159
=== "macOS"

0 commit comments

Comments
 (0)