This is a cache of https://docs.openshift.com/container-platform/4.8/cli_reference/openshift_cli/configuring-cli.html. It is a snapshot of the page at 2024-11-20T19:38:16.416+0000.
Configuring the OpenShift <strong>cli</strong> - OpenShift <strong>cli</strong> (oc) | <strong>cli</strong> tools | OpenShift Container Platform 4.8
×

Enabling tab completion

You can enable tab completion for the Bash or Zsh shells.

Enabling tab completion for Bash

After you install the OpenShift cli (oc), you can enable tab completion to automatically complete oc commands or suggest options when you press Tab. The following procedure enables tab completion for the Bash shell.

Prerequisites
  • You must have the OpenShift cli (oc) installed.

  • You must have the package bash-completion installed.

Procedure
  1. Save the Bash completion code to a file:

    $ oc completion bash > oc_bash_completion
  2. Copy the file to /etc/bash_completion.d/:

    $ sudo cp oc_bash_completion /etc/bash_completion.d/

    You can also save the file to a local directory and source it from your .bashrc file instead.

Tab completion is enabled when you open a new terminal.

Enabling tab completion for Zsh

After you install the OpenShift cli (oc), you can enable tab completion to automatically complete oc commands or suggest options when you press Tab. The following procedure enables tab completion for the Zsh shell.

Prerequisites
  • You must have the OpenShift cli (oc) installed.

Procedure
  • To add tab completion for oc to your .zshrc file, run the following command:

    $ cat >>~/.zshrc<<EOF
    if [ $commands[oc] ]; then
      source <(oc completion zsh)
      compdef _oc oc
    fi
    EOF

Tab completion is enabled when you open a new terminal.