Angular CLI - ng completion Command



This chapter explains the Angular CLI ng completion command. It includes syntax, arguments, options, and an example to show how to use this command in an angular application to enable auto-completion.

The 'ng completion' Command

The Angular CLI (Command Line Interface) provide a command called ng completion, which is used to enable shell auto-completion for angular commands and options.

It helps developers to work more efficiently by providing suggestions in the terminal. When you press the key while typing, it suggests various commands and options. This feature makes it much easier to locate and use CLI commands without needing to remember all of them.

Important! When you run your Angular application very first time using the ng serve command, CLI should prompt and ask to set up autocompletion. If you refuse it once, it will not ask again. But you can run the ng completion command to do the same thing automatically.

Syntax

Following is the syntax of the Angular CLI ng completion command −

ng completion[options]

Here,

  • options: It shows a help message for this command in the console.

Arguments

It does not require any argument.

Options

Below is a list of a few commonly used options:

Sr.No. Options & Description
1 --all

It generates a completion script of all the available shells.

2 --bash

Generates a completion script specific to the 'bash shell'.

3 --zsh

Generates a completion script specific to the 'zsh shell'.

4 --fish

Generates a completion script specific to the 'fish shell'.

5 script:

Generate a 'bash' and 'zsh' real-time type-ahead autocompletion script.

Example

The following is an example of using the "ng completion" command in an Angular application −

ng completion

When you run the above command in a code editor terminal or Command Prompt (on a Windows operating system), you might observe the following error:

PS C:\Users\Tutorialspoint\Desktop\Angular Practice\myApp> ng completion
`$SHELL` environment variable not set. Angular CLI autocompletion only supports Bash or Zsh. 
If you're on Windows, Cmd and Powershell don't support command autocompletion, but Git Bash or Windows Subsystem for Linux should work, so please try again in one of those environments.

The above error confirms that the command prompt and windows PowerShell don't use directly this command, if you want to proceed with it, make sure the git Bash is installed in your system. Then re-enter the ng completion command to see the changes.

To use the "ng completion" command (in window operating system) use the following steps:

Step 1: Download the git-bash from the below link:

Download Git Bash

Step 2: Open the downloaded file and install it in your system.

Step 3: Open the Git Bash:

Git Bash

Step 4: Run the following command in the Git Bash terminal:

ng completion
Git Bash

Step 5: Restart your terminal or run the following command:

source <(ng completion script)

Once the above command runs successfully, you will be able to see:

Git Bash

Step 6: Now enter the ng and press the <TAB> key to show available commands:

Git Bash

As you can see in the above image, all commands become available by pressing the TAB key after entering 'ng', since we have already enabled shell auto-completion for Angular.

To test for autocomplete, simply start typing ng ser<TAB>, and it should autocomplete to ng serve as follows:

Git Bash
Advertisements