This page provides instructions for configuring and using the gdcloud CLI autocomplete feature that enables you to use the <kbd>Tab</kbd> key to complete a partially entered command. This feature is available for Bash, Zsh, and Fish shells.
The gdcloud CLI autocompletion is a feature that provides suggestions for commands and options as you type. This can be helpful when you are not sure what command to use or when you want to use a command that you have not used before.

## Activate autocompletion

To activate the auto--completion feature you will need to run a command for your terminal. The gdcloud CLI autocompletion feature is available for the Linux operating system in the Bash, Zsh, and Fish shells. Use the following command to figure out which shell you use.

```bash
echo $SHELL
```

The output looks like `bin/$SHELL` where `$SHELL` is either bash, zsh, or fish.

### Bash

To load completions in your current shell session:

```bash
source <(gdcloud completion bash)
```

To load completions for every new session, run the following commands once:

```bash
gdcloud completion bash > gdcloud-completion.bash
sudo cp gdcloud-completion.bash /etc/bash_completion.d/
```

### Zsh

If shell completion is not already enabled in your environment, you must enable it. Check whether shell completion is enabled.

Check the value of the `COMP_LINE` variable. If the value of the `COMP_LINE` variable is empty, then shell completion is not enabled. You can check this value by running the following command:

```bash
echo $COMP_LINE
```

Try to use shell completion with a command. If you try to use shell completion with a command and it does not work, the shell completion is not enabled. For example, try typing the following command and pressing <kbd>Tab</kbd>. If shell completion is enabled, you must see a list of possible completions for the `ls` command.

```bash
ls
```

Check the output of the compgen -c command. If the output of the `compgen -c` command contains no commands, then shell completion is not enabled. You can run the following command to see the output of the `compgen -c` command. If shell completion is enabled, the output of the command should include a list of commands that have completion functions.

```bash
compgen -c
```

If you are not sure if shell completion is enabled in your environment, check documentation for your shell.
If shell completion is not enabled in your environment, execute the following command to enable it:

```bash
echo "autoload -U compinit; compinit" >> ~/.zshrc
```

To load completions in your current shell session:

```bash
source <(gdcloud completion zsh); compdef _gdcloud gdcloud
```

To load completions for each session, execute once:

```bash
gdcloud completion zsh > "${fpath[1]}/_gdcloud"
```

You must start a new shell for this setup to take effect.

### Fish

To load completions in your current shell session:

```bash
gdcloud completion fish | source
```

To load completions for each session, run:

```bash
gdcloud completion fish > ~/.config/fish/completions/gdcloud.fish
```

You must start a new shell for this setup to take effect.

## Use autocompletion

To use gdcloud CLI autocompletion, type the first few characters of the command that you want to use and then press the <kbd>Tab</kbd> key. If there is only one possible completion, it is automatically inserted into the command line. If the command does not autofill, then that means there are multiple possible completions and you must press the <kbd>Tab</kbd> key again to view all the possible commands.

### Autocomplete examples

Type a command partially and then press <kbd>Tab</kbd> to autocomplete the command:

```bash
gdcloud con <TAB>
```

Complete command after pressing <kbd>Tab</kbd> once:

```bash
gdcloud config
```

Type a command partially and then press <kbd>Tab</kbd> twice to see a list of all possible commands:

```bash
gdcloud clusters <TAB> <TAB>
describe get-credentials list
gdcloud clusters
```