complete - macOS


The complete command in macOS is used primarily within shell environments to manage tab-completion settings for other commands. It helps in specifying how command line arguments are parsed and suggests completions. This tool is especially useful in customizing the behavior of bash or zsh shells for better productivity in command-line operations.


complete [-abcdefgjksuv] [-pr] [-o comp-option] [-A action] [-G globpat]
         [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix]
         [-S suffix] [name ...]

Required Arguments:

  • name: Names of the commands for which the completion rules are being defined or modified.

Optional Arguments:

  • -o comp-option: Define how bash processes possible completions after considering other options.
  • -A action, -G globpat, -W wordlist, -F function, -C command, -X filterpat, -P prefix, -S suffix: Various modifiers that specify the completion behavior.


  • -a: Complete with alias names.
  • -b: Complete with builtin shell command names.
  • -c: Complete with command names.
  • -d: Complete with directory names.
  • -e: Complete with exported shell variable names.
  • -f: Complete with file names.
  • -j: Complete with job names.
  • -s: Complete with service names.
  • -u: Complete with user names.
  • -v: Complete with variables names.
  • -p: Display the current completion set.
  • -r: Remove a completion specification for each name, or all completions if no name is specified.


  1. Setting file name completion for a custom script:

    complete -f myscript

    This command allows myscript to auto-complete arguments as filenames.

  2. Complex completion command for a git alias:

    complete -o default -o nospace -F _git g

    Here, the command configures bash to use the completion function _git when completing arguments for the alias g which stands for git.

Common Issues

  • Misconfigured completion script: Incorrect syntax in bash functions or misuse of options can cause completion to fail. Make sure to reference proper function names and match completion specifications to the corresponding commands.
  • Conflicts between completions: Different scripts or user configurations might override each other. Ensure order and compatibility when configuring multiple completion behaviors.


complete can be integrated seamlessly with shell scripts or during session initialization through .bashrc or .zshrc files. For instance:

# In .bashrc or .zshrc
complete -C 'ssh' ssh
complete -C 'scp' scp
  • compgen: Displays available completion options.
  • declare: Sets shell variables and functions, useful in defining new completions.

For further reading, refer to the Bash Reference Manual or other specific documentation related to shell scripting in macOS.