Command auto-completion function

Last Updated: Sep 07, 2017

On Linux/UNIX and Mac OS systems, Alibaba Cloud CLI includes a command prompt and auto-completion function. This enables you to use the Tab key to execute partially typed commands and produces command-related prompts. This function is not installed automatically. You need to configure it manually.

The following information is required to complete the configuration:

  • The name of your Shell in use.

  • The path of alicloud_completer script.

Identify Shell

If you do not know your Shell in use, you can identify it using one of the following commands. Currently, automatic completion of bash and zsh is supported.

Method 1: Display the installation directory of Shell

Run the following command to display the installation directory of Shell. This usually matches your Shell in use unless you start another Shell after login.

  1. echo $SHELL

Method 2: Display the running processes of the current user

Run the following command to display the running processes of the current user. Among them, you can find Shell.

  1. ps

Find the alicloud-completer script

Run the following command to find the path aliyun_completer.

  1. which aliyun_completer

Enable command auto-completion

Shell type – bash

  1. Run the following command to enable command auto-completion by using the the internal command complete.

    The complete command is a bash auto-completion command. It adds the specified completion script to the executable file, so that a prompt is displayed and the automatic completion is enabled upon pressing Tab.

    1. complete -C '<path of aliyun_completer, like /usr/local/bin/aliyun_completer>' aliyuncli
  2. After the command is entered, check whether the input is correct. Enter complete, and check whether the above information is filled.

    1. complete

    If the following information is displayed, it indicates that the input is correct.

    1. complete -C <path of aliyun_completer, like /usr/local/bin/aliyun_completer > aliyuncli
  3. To ensure that command auto-completion is enabled every time when you launch bash, you need to add the auto-completion command to the Shell configuration file.

    Run the following command to add the command in Step 1 to the file named.bash_profile.

    1. vim ~/.bash_profile
    2. Add complete -C '<path of aliyun_completer, like /usr/local/bin/aliyun_completer>' aliyuncli to the end of file.

Shell type – zsh

Run the following command to use alicloud_zsh_complete.sh to implement automatic completion.

  1. source /usr/local/bin/aliyun_zsh_complete.sh
Thank you! We've received your feedback.