Linux command
compopt 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Enable filenames completion
compopt -o filenames
Enable directory completion
compopt -o dirnames
Disable default completion
compopt +o default
Add space after completion
compopt -o nospace
Remove the nospace option
compopt +o nospace
Set options for a specific command
compopt -o filenames [command_name]
说明
compopt is a Bash builtin command used within programmable completion functions to modify completion behavior dynamically. It allows completion functions to change options based on context or arguments. When called without arguments inside a completion function, compopt modifies the options for the current completion. When command names are provided, it modifies the completion specification for those commands, similar to complete -o. This command is essential for creating sophisticated completion functions that adapt their behavior based on what's being completed. For example, a function might enable filename completion only when the user is completing a file path argument.
参数
- -o _OPTION_
- Enable the specified completion option.
- +o _OPTION_
- Disable the specified completion option.
- -D
- Apply to default completion (when no specific completion is defined).
- -E
- Apply to empty command completion (completion on empty line).
- -I
- Apply to initial word completion.
- filenames
- Perform filename completion and processing (escaping, trailing slash).
- dirnames
- Perform directory name completion.
- nospace
- Do not append a space after completion.
- default
- Use default readline completion if no matches.
- bashdefault
- Use bash default completions if no matches.
- plusdirs
- Add directory names to completions.
FAQ
What is the compopt command used for?
compopt is a Bash builtin command used within programmable completion functions to modify completion behavior dynamically. It allows completion functions to change options based on context or arguments. When called without arguments inside a completion function, compopt modifies the options for the current completion. When command names are provided, it modifies the completion specification for those commands, similar to complete -o. This command is essential for creating sophisticated completion functions that adapt their behavior based on what's being completed. For example, a function might enable filename completion only when the user is completing a file path argument.
How do I run a basic compopt example?
Run `compopt -o filenames` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _OPTION_ do in compopt?
Enable the specified completion option.