How to setup tab completions for WP-CLI commands

WP CLI official logo - WordPress command line

WP-CLI is the command line interface for WordPress. If you have not setup WP-CLI yet, see steps to setup WP-CLI.

There is tab completions feature which is generally missed in the installation process. Here are the easy few steps to add tab completions for the WP-CLI. I am using Ubuntu here for example. But it would be similar for UNIX environment.

You need to have bash file for setting up autocomplete in the terminal. WP-CLI has already provided bash file. You can download it from Github repo of WP-CLI.

Put that downloaded wp-completion.bash file under the folder you like. Say you keep under completions in your Home directory.
/home/nilambar/completions/wp-completion.bash

Now, open your .bashrc file with your favorite text editor.

vi ~/.bashrc

In that file, put code to source your completion file. Syntax will be similar to:

source /FULL/PATH/TO/wp-completion.bash

In our example, it would be:

source /home/nilambar/completions/wp-completion.bash

Save your file and close it. Now you need to source your bashrc file to activate your new code for the terminal.

source ~/.bashrc

Then restart the terminal.

Its that simple, no? But it will be very handy to use WP-CLI. I am sure you will love it.

3 thoughts on “How to setup tab completions for WP-CLI commands

  1. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

Leave a Reply

Your email address will not be published. Required fields are marked *