Linux command
bash-completion 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Load bash completions
source /usr/share/bash-completion/bash_completion
Install completions
sudo cp [command_completion.bash] /usr/share/bash-completion/completions/[command]
Install completions
cp [command_completion.bash] ~/.local/share/bash-completion/completions/[command]
List loaded completions
complete -p
Remove a completion
complete -r [command]
Create a simple completion
complete -W "[option1 option2 option3]" [command]
说明
bash-completion is a collection of shell functions that provide programmable command-line completion for Bash. When you press Tab, it completes not just filenames but command options, subcommands, hostnames, and other context-specific values. The system works by defining completion specifications that tell Bash how to generate suggestions for specific commands. Specifications can use word lists, functions, or external commands to generate completions dynamically. Completions are stored in /usr/share/bash-completion/completions/ (or /etc/bash_completion.d/ on older systems). They are loaded on-demand when Tab is first pressed for a command, improving shell startup time.
参数
- complete -p _command_
- Print current completion specification for command(s).
- complete -r _command_
- Remove completion specification for command.
- complete -W _wordlist_ _command_
- Define completion using a word list.
- complete -F _function_ _command_
- Use a shell function for completion.
- complete -C _command_ _command_
- Use a command's output for completion.
- complete -o _option_ _command_
- Enable completion options (filenames, dirnames, default, etc.).
- compgen
- Generate completions programmatically in completion functions.
FAQ
What is the bash-completion command used for?
bash-completion is a collection of shell functions that provide programmable command-line completion for Bash. When you press Tab, it completes not just filenames but command options, subcommands, hostnames, and other context-specific values. The system works by defining completion specifications that tell Bash how to generate suggestions for specific commands. Specifications can use word lists, functions, or external commands to generate completions dynamically. Completions are stored in /usr/share/bash-completion/completions/ (or /etc/bash_completion.d/ on older systems). They are loaded on-demand when Tab is first pressed for a command, improving shell startup time.
How do I run a basic bash-completion example?
Run `source /usr/share/bash-completion/bash_completion` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does complete -p _command_ do in bash-completion?
Print current completion specification for command(s).