# Configure BASH Autocomplete for Kubectl CLI on MacOS X

## Problem

When working with the Kubectl CLI often, it is much more efficient to be able to autocomplete long commands and resource names.

## Environment

* Platform9 Managed Kubernetes - All Versions
* MacOS X - v10.13.x

## Procedure

1. Install the [Homebrew](https://brew.sh/) binary.

{% tabs %}
{% tab title="command" %}

```ruby
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```

{% endtab %}
{% endtabs %}

2. Install the *bash-completion* package.

{% tabs %}
{% tab title="command" %}

```bash
$ brew install bash-completion
```

{% endtab %}
{% endtabs %}

3. If you do not have a dedicated terminal and need to enable autocompletion on the fly, run the following command.

{% tabs %}
{% tab title="command" %}

```bash
$ source <(kubectl completion zsh)
```

{% endtab %}
{% endtabs %}

Otherwise, append the following command to your *.zshrc* file to enable autocomplete persistently.

{% tabs %}
{% tab title="command" %}

```bash
$ echo "source <(kubectl completion zsh)" >> ~/.zshrc
```

{% endtab %}
{% endtabs %}

If above command fails with error "**Command not found: compdef"** then run below command to load **compinit:**

{% tabs %}
{% tab title="Javascript" %}

```javascript
$ autoload -Uz compinit
$ compinit
```

{% endtab %}
{% endtabs %}

## Additional Information

See [Kubernetes Reference: Kubectl Cheat Sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/) for more handy commands and configurations.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform9.com/kb/pmk/how-to/configure-bash-autocomplete-for-kubectl-cli-on-macos-x.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
