Thanks to visit codestin.com
Credit goes to docs.jfrog.com

Enable Shell Auto-Completion for JFrog CLI

If you're using JFrog CLI from a bash, zsh, or fish shell, you can install JFrog CLI's auto-completion scripts to improve your command-line experience. Auto-completion helps save time and reduces errors by suggesting potential command options and arguments as you type.

Auto-completion allows you to:

  • Increase command-line efficiency by reducing typing
  • Minimize typographical errors in commands and options
  • Discover available commands and options through in-line suggestions

This topic covers the following tasks:


Prerequisites

Before enabling auto-completion, ensure the following:

  • JFrog CLI is installed. Run jf --version to confirm. If not installed, see Download and Install the JFrog CLI.
  • Your shell is identified. This page covers bash, zsh, and fish. Check your current shell with echo $SHELL.
  • Oh My Zsh path only: Oh My Zsh must already be installed. If you are not using Oh My Zsh, skip to Other Installation Methods.
  • Fish path only: The fish shell must be installed and set as your shell to use fish completions.

Enable Auto-Completion

The method of enabling auto-completion varies based on the shell you are using (bash, zsh, or fish).

Install JFrog CLI with Homebrew

If you're installing JFrog CLI using Homebrew, the bash, zsh, or fish auto-complete scripts are automatically installed. You need to ensure that your .bash_profile or .zshrc files are correctly configured. For more information, see the Homebrew shell completion documentation.

Homebrew installs completion scripts to the following locations:

  • zsh: $(brew --prefix)/share/zsh/site-functions/ (for example, /opt/homebrew/share/zsh/site-functions/ on Apple Silicon)
  • bash: $(brew --prefix)/etc/bash_completion.d/
  • fish: $(brew --prefix)/share/fish/vendor_completions.d/

To verify that the JFrog CLI completion script was installed:

  • Run the following command:
ls $(brew --prefix)/share/zsh/site-functions/ | grep jf

If no output is returned, see the Homebrew shell completion documentation to configure your shell profile, or use the manual installation method instead.

Using Oh My Zsh?

📘

Prerequisite

Oh My Zsh must already be installed. If you are not using Oh My Zsh, skip to Other Installation Methods.

To enable JFrog CLI auto-completion with Oh My Zsh:

  1. Open your zsh configuration file, located at $HOME/.zshrc, with any text editor. For example:
nano $HOME/.zshrc
  1. Locate the line starting with plugins=.

  2. Add jfrog to the list of plugins. For example:

plugins=(git mvn npm sdk jfrog)
  1. Save and close the file.

  2. Apply the changes by running the following command:

source $HOME/.zshrc

Other Installation Methods

If you're not using Homebrew or Oh My Zsh, you can manually install the auto-completion scripts for your specific shell:

For Bash

To install auto-completion for Bash:

  • Run the following command:
jf completion bash --install

This generates a completion script at ~/.jfrog/jfrog_bash_completion and displays the following output:

Generated bash completion script at /Users/<username>/.jfrog/jfrog_bash_completion.
To activate auto-completion on this shell only, source the completion script by running the following command:

source /Users/<username>/.jfrog/jfrog_bash_completion

To activate auto-completion permanently, add the `source` line to `~/.bashrc` or `~/.bash_profile`, depending on your operating system.

To activate permanently, add the following line to your ~/.bashrc or ~/.bash_profile:

source ~/.jfrog/jfrog_bash_completion

Then restart your terminal or run source ~/.bashrc.

For Zsh

To install auto-completion for Zsh:

  • Run the following command:
jf completion zsh --install

This generates a completion script at ~/.jfrog/jfrog_zsh_completion and displays the following output:

Generated zsh completion script at /Users/<username>/.jfrog/jfrog_zsh_completion.
To activate auto-completion on this shell only, source the completion script by running the following 3 commands:

autoload -Uz compinit
compinit
source /Users/<username>/.jfrog/jfrog_zsh_completion

To activate auto-completion permanently, add the 3 commands to `~/.zshrc`.

Zsh activation: Zsh requires 3 commands to activate completion. To activate permanently, add the following lines to your ~/.zshrc:

autoload -Uz compinit
compinit
source ~/.jfrog/jfrog_zsh_completion

Then restart your terminal or run source ~/.zshrc.

📘

Zsh compinit

If your ~/.zshrc already calls compinit (common when using a zsh framework or plugin manager), you only need to add the source line. Adding a second compinit call is harmless but unnecessary.

For Fish

📘

Prerequisite

The fish shell must be installed and set as your shell to use fish completions. To check, run which fish. If fish is not installed, see fishshell.com for installation instructions.

To install auto-completion for Fish:

  • Run the following command:
jf completion fish --install

This generates a completion script at ~/.config/fish/completions/jf.fish and displays the following output:

Generated fish completion script at /Users/<username>/.config/fish/completions/jf.fish

No additional configuration is required. Fish automatically loads completion scripts from the ~/.config/fish/completions/ directory. Restart your fish shell or open a new terminal session.

📘

Fish completion file size

The fish completion script is significantly larger than the bash or zsh equivalents (approximately 300 KB) because it pre-computes completions for all commands and flags. This is expected behavior and does not affect performance during normal use.

📘

Re-running the install command

If you run jf completion <shell> --install again, the existing completion script is silently overwritten with a fresh copy. This is safe to do after upgrading JFrog CLI.


Verifying Installation

After installing the completion scripts, you can verify that auto-completion works by typing jf followed by pressing the Tab key. You should see a list of available top-level commands and subcommands.

If auto-completion is working correctly, pressing Tab after jf displays commands such as config, rt, completion, login, and many others depending on your CLI version, installed plugins, and enabled features. The list is substantially longer than a few entries. JFrog CLI exposes commands for Artifactory, Xray, Distribution, Lifecycle, package managers, and more.

📘

Note

If no suggestions appear after pressing Tab, ensure you have sourced the completion script in your current shell session, or opened a new terminal after adding the source line to your shell profile.


Generate Scripts without Installation

If you prefer to output the completion script to stdout without installing it, omit the --install flag:

# Output bash completion script to stdout
jf completion bash

# Output zsh completion script to stdout
jf completion zsh

# Output fish completion script to stdout
jf completion fish

You can redirect the output to a custom location:

jf completion bash > /custom/path/jfrog_completion

Command Reference

The following table summarizes completion commands.

CommandSynopsisKey Option
jf completion bashjf completion bash [options]--install installs the script instead of printing to stdout
jf completion zshjf completion zsh [options]--install installs the script instead of printing to stdout
jf completion fishjf completion fish [options]--install installs the script instead of printing to stdout

All 3 commands accept 1 option. The following table describes that option.

FlagDefaultDescription
--installfalseWhen present, installs the completion script to the default path instead of printing to standard output

For detailed usage of each shell's completion command, see the how-to sections in this topic.


What’s Next

For further customization, review all available environment variables.