|
| 1 | +.. _mcli-autocomplete: |
| 2 | + |
| 3 | +======================================= |
| 4 | +Enable Autocomplete for the {+mcli+} |
| 5 | +======================================= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +You can enable autocomplete for {+mcli+} commands to see available |
| 16 | +commands and their syntax directly in your shell. |
| 17 | + |
| 18 | +Enable Autocomplete |
| 19 | +------------------- |
| 20 | + |
| 21 | +.. tabs:: |
| 22 | + |
| 23 | + .. tab:: Homebrew Installation |
| 24 | + :tabid: Homebrew |
| 25 | + |
| 26 | + If you installed the {+mcli+} with Homebrew, autocomplete |
| 27 | + functionality is included with the installation. You must |
| 28 | + configure your shell to enable its completion support. To enable |
| 29 | + autocomplete for your shell, refer to the |
| 30 | + `Homebrew Documentation |
| 31 | + <https://docs.brew.sh/Shell-Completion>`__. |
| 32 | + |
| 33 | + .. tab:: Other Installation |
| 34 | + :tabid: non-Homebrew |
| 35 | + |
| 36 | + If you did not install the {+mcli+} with Homebrew, the procedure |
| 37 | + to enable autocomplete depends on the shell in which you |
| 38 | + run the {+mcli+}. |
| 39 | + |
| 40 | + Z Shell |
| 41 | + ~~~~~~~ |
| 42 | + |
| 43 | + If you use ``zsh`` to run the {+mcli+}, add the following to your |
| 44 | + ``~/.zshrc``: |
| 45 | + |
| 46 | + .. code-block:: sh |
| 47 | + |
| 48 | + autoload -Uz compinit |
| 49 | + compinit |
| 50 | + |
| 51 | + source <(mongocli completion zsh) |
| 52 | + compdef _mongocli mongocli |
| 53 | + |
| 54 | + Run the following command to reload your ``zsh`` profile: |
| 55 | + |
| 56 | + .. code-block:: sh |
| 57 | + |
| 58 | + source ~/.zshrc |
| 59 | + |
| 60 | + Bash |
| 61 | + ~~~~ |
| 62 | + |
| 63 | + If you use Bash to run the {+mcli+}, add the following to your |
| 64 | + ``~/.bash_profile``: |
| 65 | + |
| 66 | + .. code-block:: sh |
| 67 | + |
| 68 | + eval "$(mongocli completion bash)" |
| 69 | + |
| 70 | + Run the following command to reload your Bash profile: |
| 71 | + |
| 72 | + .. code-block:: sh |
| 73 | + |
| 74 | + source ~/.bash_profile |
| 75 | + |
| 76 | +Use ``Tab`` to Autocomplete Commands |
| 77 | +------------------------------------ |
| 78 | + |
| 79 | +Once you have autocomplete configured, you can autocomplete commands by |
| 80 | +typing ``mongocli`` in your shell and pressing the ``Tab`` key. Press |
| 81 | +``Tab`` multiple times to cycle through available autocompletion |
| 82 | +options. |
| 83 | + |
| 84 | +You can press ``Tab`` at any stage of writing your command to see |
| 85 | +available autocomplete options. |
| 86 | + |
| 87 | +Examples |
| 88 | +~~~~~~~~ |
| 89 | + |
| 90 | +When you type ``mongocli`` in your shell and press ``Tab``, the output |
| 91 | +resembles the following: |
| 92 | + |
| 93 | +.. code-block:: none |
| 94 | + :copyable: false |
| 95 | + |
| 96 | + atlas -- Atlas operations. |
| 97 | + cloud-manager -- Cloud Manager operations. |
| 98 | + completion -- Generate shell completion scripts |
| 99 | + config -- Configure a profile to store access settings for your MongoDB deployment. |
| 100 | + help -- Help about any command |
| 101 | + iam -- Organization and projects operations. |
| 102 | + ops-manager -- Ops Manager operations. |
| 103 | + |
| 104 | +If you type a specific property such as ``atlas`` as part of your |
| 105 | +command, you can see autocompletion options for your selected |
| 106 | +property. |
| 107 | + |
| 108 | +For example, when you type ``mongocli atlas`` in your shell and press |
| 109 | +``Tab``, the output resembles the following: |
| 110 | + |
| 111 | +.. code-block:: none |
| 112 | + :copyable: false |
| 113 | + |
| 114 | + alerts -- Manage alerts for your project. |
| 115 | + backups -- Manage backups for your project. |
| 116 | + clusters -- Manage clusters for your project. |
| 117 | + dbusers -- Manage database users for your project. |
| 118 | + events -- Manage events for your project. |
| 119 | + logs -- Download host logs for your project. |
| 120 | + metrics -- Get measurements on the state of the MongoDB process. |
| 121 | + processes -- Manage MongoDB processes for your project. |
| 122 | + whitelist -- Manage the IP whitelist for a project. |
0 commit comments