# Enabling shell autocompletion
The Kubebuilder completion script can be generated with the command `kubebuilder completion [bash|fish|powershell|zsh]`.
Note that sourcing the completion script in your shell enables Kubebuilder autocompletion.

## Bash

<aside class="note" role="note">
<p class="note-title">Prerequisites for Bash</p>

The completion Bash script depends on [bash-completion](https://github.com/scop/bash-completion), which means that you have to install this software first (you can test if you have bash-completion already installed). Also, ensure that your Bash version is 4.1+.

```bash
$ bash --version
```

</aside>

- Check that bash is an available shell:

    ```bash
    cat /etc/shells | grep '^.*/bash'
    ```

- If not, add bash to `/etc/shells`. For example, if bash is at `/usr/local/bin/bash`:

    ```bash
    echo "/usr/local/bin/bash" >> /etc/shells
    ```

- Make sure the current user uses bash as their shell.

    ```bash
    chsh -s /usr/local/bin/bash
    ```

- Add following content to `~/.bash_profile` or `~/.bashrc`

    ```bash
    # kubebuilder autocompletion
    if [ -f /usr/local/share/bash-completion/bash_completion ]; then
        . /usr/local/share/bash-completion/bash_completion
    fi
        . <(kubebuilder completion bash)
    ```

- Restart terminal for the changes to be reflected or `source` the changed bash file.

    ```bash
    . ~/.bash_profile
    ```

## Zsh

Follow a similar protocol for `zsh` completion.

## Fish

```bash
source (kubebuilder completion fish | psub)
```
