Install wp-cli bash completion file
leeps opened this issue · 9 comments
wp-cli provides a bash-completion configuration, see https://github.com/wp-cli/wp-cli/blob/master/utils/wp-completion.bash.
The .deb packes should include and install this file.
Installing an autocompletion file by default will slow down the shell for every single operation, even if WP-CLI is not being used at all.
Closing for now, as I think this is usually reserved for manual changes intended by the user instead.
@schlessera We could mention this in the deb's description
https://github.com/wp-cli/wp-cli-bundle/blob/master/utils/wp-cli-updatedeb.sh#L36
I was under the impression that once the shell is started, unless a completion is requested by the user (pressing the TAB key twice per example), there are no downsides or even side effects to having completion file. In fact, most major/well-known deployments install/have completion files.
systemd, yum, dnf, perl, lvm, lsblk, apt-get, dpkg, postfix...
as an example, my /usr/share/bash-completion/completions/ (latest fedora) directory contains 639 completion files (not counting links, actual files) to this date. (389 on an older box witth ubuntu server)
Adding completion is candy to users, and i believe is greatly appreciated
Yes, if you load 1 zillion competition functions (see set | page
or declare -F
) they must load into every Bash instance. Although only the current command's function runs on TAB
Why not build bash completion as separate package?
I guess you could include instructions on how to do it for those who are less familiar with the process.
- Make sure your
.bashrc
contains the following (in case it does not):
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
- Copy
wp-completion.bash
to appropriate folder:
curl -o /usr/share/bash-completion/completions/wp https://github.com/wp-cli/wp-cli/blob/master/utils/wp-completion.bash
special note: you need to rename file to wp
otherwise it will not be picked up (explained here)
- Either re-start your session or do
source ~/.bashrc
Disclaimer: it could be possible this is not the best approach but I suppose something (a starting point) is better than nothing since there is no official guide from wp-cli on how to enable bash completion
Why not build bash completion as separate package?
If you use Mac and brew, they provide a package for that.
- Copy
wp-completion.bash
to appropriate folder:curl -o /usr/share/bash-completion/completions/wp https://github.com/wp-cli/wp-cli/blob/master/utils/wp-completion.bash
The URL should be https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
. Otherwise, you'll get an HTML file instead of the actual bash script.
So, the correct command is:
curl -o /usr/share/bash-completion/completions/wp https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
I got a git.io link to the raw completion file. You can now use https://git.io/JtqGu
curl -sLko /usr/share/bash-completion/completions/wp https://git.io/JtqGu