|
1 |
| -To enable Bash and Zsh real-time type-ahead autocompletion, run |
2 |
| -`ng completion` and restart your terminal. |
| 1 | +Setting up autocompletion configures your terminal, so pressing the `<TAB>` key while in the middle |
| 2 | +of typing will display various commands and options available to you. This makes it very easy to |
| 3 | +discover and use CLI commands without lots of memorization. |
3 | 4 |
|
4 |
| -Alternatively, append `source <(ng completion script)` to the appropriate `.bashrc`, |
5 |
| -`.bash_profile`, `.zshrc`, `.zsh_profile`, or `.profile` file. |
| 5 | + |
| 8 | + |
| 9 | +## Automated setup |
| 10 | + |
| 11 | +The CLI should prompt and ask to set up autocompletion for you the first time you use it (v14+). |
| 12 | +Simply answer "Yes" and the CLI will take care of the rest. |
| 13 | + |
| 14 | +``` |
| 15 | +$ ng serve |
| 16 | +? Would you like to enable autocompletion? This will set up your terminal so pressing TAB while |
| 17 | +typing Angular CLI commands will show possible options and autocomplete arguments. (Enabling |
| 18 | +autocompletion will modify configuration files in your home directory.) Yes |
| 19 | +Appended `source <(ng completion script)` to `/home/my-username/.bashrc`. Restart your terminal or |
| 20 | +run: |
| 21 | +
|
| 22 | +source <(ng completion script) |
| 23 | +
|
| 24 | +to autocomplete `ng` commands. |
| 25 | +
|
| 26 | +# Serve output... |
| 27 | +``` |
| 28 | + |
| 29 | +If you already refused the prompt, it won't ask again. But you can run `ng completion` to |
| 30 | +do the same thing automatically. |
| 31 | + |
| 32 | +This modifies your terminal environment to load Angular CLI autocompletion, but can't update your |
| 33 | +current terminal session. Either restart it or run `source <(ng completion script)` directly to |
| 34 | +enable autocompletion in your current session. |
| 35 | + |
| 36 | +Test it out by typing `ng ser<TAB>` and it should autocomplete to `ng serve`. Ambiguous arguments |
| 37 | +will show all possible options and their documentation, such as `ng generate <TAB>`. |
| 38 | + |
| 39 | +## Manual setup |
| 40 | + |
| 41 | +Some users may have highly customized terminal setups, possibly with configuration files checked |
| 42 | +into source control with an opinionated structure. `ng completion` only ever appends Angular's setup |
| 43 | +to an existing configuration file for your current shell, or creates one if none exists. If you want |
| 44 | +more control over exactly where this configuration lives, you can manually set it up by having your |
| 45 | +shell run at startup: |
| 46 | + |
| 47 | +```bash |
| 48 | +source <(ng completion script) |
| 49 | +``` |
| 50 | + |
| 51 | +This is equivalent to what `ng completion` will automatically set up, and gives power users more |
| 52 | +flexibility in their environments when desired. |
| 53 | + |
| 54 | +## Platform support |
| 55 | + |
| 56 | +Angular CLI supports autocompletion for the Bash and Zsh shells on MacOS and Linux operating |
| 57 | +systems. |
| 58 | + |
| 59 | +Windows does not support autocompletion in native shells, such as Cmd and Powershell. However, |
| 60 | +the Angular CLI supports Git Bash and |
| 61 | +[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/) using Bash or Zsh. |
| 62 | + |
| 63 | +## Global install |
| 64 | + |
| 65 | +Autocompletion works by configuring your terminal to invoke the Angular CLI on startup to load the |
| 66 | +setup script. This means the terminal must be able to find and execute the Angular CLI, typically |
| 67 | +through a global install that places the binary on the user's `$PATH`. If you get |
| 68 | +`command not found: ng`, make sure the CLI is installed globally which you can do with the `-g` |
| 69 | +flag: |
| 70 | + |
| 71 | +```bash |
| 72 | +npm install -g @angular/cli |
| 73 | +``` |
0 commit comments