Newer Version Available

This content describes an older version of this product. View Latest

Autocomplete Salesforce CLI Commands and Flags

Use autocomplete to quickly find the exact Salesforce CLI command and flag you want to execute.

You must set up the autocomplete feature before you can use it. How you set it up depends on the shell you use to execute Salesforce CLI commands. Autocomplete supports these shells:

  • Bash: macOS and Linux
  • Z shell (zsh): macOS and Linux
  • PowerShell: Typically used on Microsoft Windows, although you can also install PowerShell on macOS and Linux.

Determine Which Shell You’re Using

Are you unsure if you’re running Bash, zsh, or Powershell? Here are some tips.

  • From your terminal or command window, run this command:
    1echo $0

    If you’re using either Bash or zsh, the command output includes the terms bash or zsh, respectively. This example shows possible output on the Bash shell.

    1echo $0
    2-bash
  • If you’re on PowerShell, this command returns version information.
    1$PSVersionTable

    Here’s some sample output.

    1Name                           Value
    2----                           -----
    3PSVersion                      7.3.9
    4PSEdition                      Core
    5GitCommitId                    7.3.9
    6OS                             Microsoft Windows 10.0.22621
    7Platform                       Win32NT
    8PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    9PSRemotingProtocolVersion      2.3
    10SerializationVersion           1.1.0.1
    11WSManStackVersion              3.0

Configure Autocomplete for Bash and Z Shell

Bash and Z shell (zsh) are available on macOS and Linux by default.
  1. Open a terminal window.
  2. Run this command, which builds the autocomplete cache on your computer:
    1sf autocomplete
  3. Follow the displayed instructions, which reflect the shell you’re currently using.
If autocomplete doesn’t work immediately after configuration, open a new terminal window and try again.

After you update Salesforce CLI to a new version, run sf autocomplete --refresh-cache to ensure that autocomplete works correctly on any new commands.

Configure Autocomplete for PowerShell

PowerShell is available on Microsoft Windows by default. You can also install it on macOS or Linux if you prefer it to Bash or Z shell. 
  1. Open a PowerShell command window.
  2. Run this command, which builds the autocomplete cache on your computer:
    1sf autocomplete powershell
  3. Follow the displayed instructions.
If autocomplete doesn’t work immediately after configuration, open a new PowerShell command window and try again.

After you update Salesforce CLI to a new version, run sf autocomplete --refresh-cache to ensure that autocomplete works correctly on any new commands.

Use Autocomplete

Partially type a Salesforce CLI command and then press the tab key (<TAB>) to autocomplete it. The autocomplete feature also works on Salesforce CLI flags and their values. Depending on the shell you're using, you might have to type <TAB> twice to get completion suggestions; keep tabbing until you see something.

Let’s look at some examples using Z shell (zsh). In a terminal or command window, type sf, a space, and then <TAB> until you see the full list of top-level topics and commands with their summaries.

zsh terminal showing autocomplete suggestions for 'sf <TAB>'.

Let’s say you want to deploy metadata from your Salesforce DX project; the project topic looks promising! To see the list of sub-topics under project, type the letters pr and then <TAB>.

zsh terminal showing autocomplete suggestions for 'sf project <TAB>'.

The output includes a deploy sub-topic; we’re getting there! To drill down, type the letters dep and <TAB>, and the commands in the deploy sub-topic are displayed. Keep typing and tabbing this way until you get to the full command to deploy metadata, which is project deploy start.

Now that you found the correct command, you probably now want to see the available flags. Simply type - (hyphen) and <TAB> to see the full list of flags, with their short and long names and summaries:

zsh terminal showing autocomplete suggestions for 'sf project deploy start - <TAB>'.

Type the first letter of a flag, then <TAB> until you’ve autocompleted the flag name.

You can also use autocomplete to specify a value for some flags. For example, if your current directory is a Salesforce DX project and you want to specify a manifest file for the --manifest flag, press <TAB> after the flag to see a list of files. Then enter the first letter and <TAB> until you complete the name of the file, such as package.xml.

zsh terminal showing autocomplete suggestions for 'sf project deploy start --manifest <TAB>'.