PM2 — Command Line Autocompletion

Everyone is seeking for productivity boosts day by day, like learning new shortcuts in your favorite IDE, a new command on the Unix shell or something else. If you’re just starting out or already familiar with PM2 commands, it’s always nice to have an auto-completion feature. This post will show you how to install the auto-completion for the PM2 command line utility.

PM2 Series Overview

Setup Auto-Completion

Actually, PM2 already ships with this feature integrated but it isn’t installed by default. You need to run the following command to add a script to your .bashrc or .zshrc file. Keep an eye on your PM2 version, because the command has changed within the 1.0 release.

PM2 0.15.x and lower

pm2 autocompletion install  

PM2 1.0.0 and newer

pm2 completion install  

If you’re looking into your .bashrc or .zshrc file, you’ll notice the following block at the bottom of the file:

### credits to npm for the completion file model
# Installation: pm2 completion >> ~/.bashrc  (or ~/.zshrc)


if type complete &>/dev/null; then  
# … code code code …

You won’t have PM2’s auto-completion feature enabled for your current terminal session. There’re two options to benefit from auto-completion:

  • just open a new terminal tab or restart your terminal utility
  • reload your current .bashrc or .zshrc file using the source command: source ~/.bashrc or source ~/.zshrc

Ultimately, you’re able to use the tab key in combination with the pm2 command.

That’s it. You’ll notice that auto-completion not only suggests commands, but also usable options. To illustrate the feature, just type pm2 restart and press the tab key. If you have already app processes managed by PM2, the suggestions will print out the applications names as valid options.

What Comes Next

The PM2 auto-completion feature is useful in various situations. Even if you’re an experienced system administrator, it will save you some time to let suggest available options to be passed as an argument to your PM2 command.

The next post in this series will explain PM2’s integrated module system. This module system allows you to extend the default PM2 functionality with 3rd party plugins.

Explore the Library

Find interesting tutorials and solutions for your problems.