# SingleStore Toolbox Command Auto-Completion

As of Toolbox 1.6.6, the \[Tab] key can be used to auto-complete Toolbox commands in both the `bash` and `zsh` shells when Toolbox is installed via `.rpm` and `.deb` packages, as well as via tarball with some additional configuration.

> **❗ Important**: The `bash-completion` package must be installed on a host that has SSH access to all hosts in the cluster. Typically, this is the Master Aggregator host.Toolbox is installed when [deploying a new self-managed cluster](https://docs.singlestore.com/db/v9.1/deploy/linux.md), or may be [installed manually](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/cluster-management-with-tools/singlestore-tools-installation.md), typically on the cluster’s Master Aggregator host.

## Install `bash-completion`

1. Determine if the `bash-completion` package is installed.

   **Red Hat Distributions**
   ```shell
   sudo yum list installed | grep bash-completion

   ```
   ```output

   bash-completion.noarch                      1:2.1-8.el7                @base    
   libvirt-bash-completion.x86_64              4.5.0-36.el7_9.3           @updates

   ```
   **Debian Distributions**
   ```shell
   sudo dpkg-query --list | grep bash-completion

   ```
   ```output

   ii  bash-completion        1:2.10-1ubuntu1        all 
   programmable completion for the bash shell

   ```

2. If `bash-completion` is not installed or is earlier than version 2.7, install the latest `bash-completion` package.

   **Red Hat Distributions**
   ```shell
   sudo yum install bash-completion

   ```
   **Debian Distributions**
   ```shell
   sudo apt install bash-completion

   ```

## Copy the Auto-Completion Script

> **❗ Important**: This step is only required for tarball-based Toolbox installs. If Toolbox has been installed using `.deb` or `.rpm` packages, skip this step.

1. Copy the Toolbox auto-completion script to the `/etc/bash_completion.d` directory.
   ```shell
   sudo cp <path-to-toolbox>/sdb-autocomplete/bash-completion-sdb-tools /etc/bash_completion.d/

   ```
   where `<path-to-toolbox>` is the full path to the folder that contains the Toolbox binaries (the folder that is created when the Toolbox `.tar.gz` file is extracted).

## Configure Your Shell

This section demonstrates how to configure `bash` and `zsh` shells to enable the Toolbox auto-completion feature for terminal sessions.

## bash

You may use this feature by manually sourcing the `bash-completion-sdb-tools` file in each new terminal session.

```shell
source /etc/bash_completion.d/bash-completion-sdb-tools

```

To automatically enable this feature in each new terminal session:

1. Add the following command to your shell profile, such as the `~/.bashrc` file, or the `~/.bash_profile` file.
   ```shell
   echo "source /etc/bash_completion.d/bash-completion-sdb-tools" >> ~/.bashrc

   ```
   – *or* –
   ```shell
   echo "source /etc/bash_completion.d/bash-completion-sdb-tools" >> ~/.bash_profile

   ```

2. This feature is now enabled for each new terminal session. For those terminal sessions that are already open, source your shell profile to use this feature.
   ```shell
   source ~/.bashrc

   ```
   – *or* –
   ```shell
   source ~/.bash_profile

   ```

## zsh

To automatically enable this feature in each new terminal session:

1. Add the following command to your `.zshrc` file.

   **For `.rpm` or `.deb` package installs**
   ```shell
   echo 'fpath=( /usr/share/sdb/zsh "${fpath[@]}" )' >> ~/.zshrc

   ```
   **For tarball installs**
   ```shell
   echo 'fpath=( <path-to-toolbox>/sdb-autocomplete "${fpath[@]}" )' >> ~/.zshrc

   ```
   where `<path-to-toolbox>` is the full path to the folder that contains the Toolbox binaries (the folder that is created when the `.tar.gz` file is extracted).

2. Add the following command to your `.zshrc` file.
   ```shell
   echo "autoload -U compinit; compinit" >> ~/.zshrc

   ```

3. This feature is now enabled for each new terminal session. For those terminal sessions that are already open, source your shell profile to use this feature.
   ```shell
   source ~/.zshrc

   ```

## Using Toolbox Auto-Completion

When entering a Toolbox command such as `sdb-admin`, `sdb-deploy`, `sdb-report`, and `sdb-toolbox-config`, press the \[Tab] key to see a list of available sub-commands and flags.

```shell
sdb-deploy [Tab]

```

**For tarball installs**, run this command from the folder that is created when the Toolbox `.tar.gz` file is extracted.

```shell
./sdb-deploy [Tab]

```

This will display the list of available sub-commands (with a description of the command if using `zsh`):

```shell
cluster-in-a-box       destroy-cluster        env
generate-cluster-file  install                list-versions
setup-cluster          ui                     uninstall              
upgrade                version

```

**Note**: In `zsh`, you may select a sub-command by pressing the \[Tab] key repeatedly.

## Example

To complete `sdb-deploy install --file-path`, begin typing the command and press the \[Tab] key.

```shell
sdb-deploy i[Tab]

```

This will auto-complete to the `install` sub-command:

```shell
sdb-deploy install

```

You may then use the same method to find available flags and auto-complete the rest of the command.

Where:

```shell
sdb-deploy install --fi[Tab]

```

becomes:

```shell
sdb-deploy install --file-path

```

## Resources

Refer to the [SingleStore Tools Reference](https://docs.singlestore.com/db/v9.1/reference/singlestore-tools-reference.md) for more information on the available sub-commands and flags for each Toolbox command.

***

Modified at: June 22, 2022

Source: [/db/v9.1/user-and-cluster-administration/cluster-management-with-tools/singlestore-toolbox/singlestore-toolbox-command-auto-completion/](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/cluster-management-with-tools/singlestore-toolbox/singlestore-toolbox-command-auto-completion/)

(An index of the documentation is available at /llms.txt)
