compopt
Modify or display completion options
TLDR
Print the completion options for given command
Enable or disable a completion option of a command
Print the options for the currently executing completion
Enable or disable a completion option of a command
SYNOPSIS
compopt [-D | -E | -I] [-o option] [name ...]
PARAMETERS
-D
Display the default completion option list for the current command
-E
Remove completion options for any names that are not found
-I
Remove completion options for names that are not function names
-o option
Enable or disable the specified option (repeatable) for each name
name ...
Completion function names to modify (defaults to current command)
DESCRIPTION
compopt is a Bash shell builtin used in programmable completion functions to enable, disable, or query completion options dynamically. It allows customization of tab-completion behavior for commands or functions, such as restricting to filenames (-o default), directories (-o dirnames), no space after completion (-o nospace), or case-insensitive matching (-o nocaseglob).
Typically invoked inside a complete-defined function (e.g., _comp_foo), it modifies options for the current command or specified names. Without options, it prints current settings like complete -p. Flags -D, -E, -I handle defaults and cleanup. This provides context-aware completion, improving shell interactivity without global changes.
CAVEATS
Bash 4.0+ builtin only; not portable to other shells.
Intended for use inside completion functions, not direct invocation.
Options mirror those of complete; invalid options ignored.
USAGE EXAMPLE
In a completion function:compopt -o nospace -o default
Disables space insertion and defaults to filenames.
QUERY EXAMPLE
compopt -o
Shows current options for the command.
HISTORY
Introduced in Bash 4.0 (February 2009) to support dynamic option changes in completion scripts, enhancing flexibility over static complete settings.


