diff --git a/pages/common/compgen.md b/pages/common/compgen.md index e3c9332b82e231..88f7b6aab8ca1a 100644 --- a/pages/common/compgen.md +++ b/pages/common/compgen.md @@ -1,15 +1,21 @@ # compgen -> A built-in command for auto-completion in Bash, which is called on pressing `` key twice. +> Bash built-in command for generating possible completion matches in Bash. +> Usually used within custom completion functions. +> See also: `complete`, `compopt`. > More information: . -- List all commands that you could run: +- List all shell built-ins, aliases, functions and executables that you could run: `compgen -c` -- List all commands that you could run that start with a specified string: +- List all commands that you could run that start with a specified string and save results to `COMPREPLY`: -`compgen -c {{str}}` +`compgen -V COMPREPLY -c {{str}}` + +- Match against a wordlist: + +`compgen -W "{{apple orange banana}}" {{a}}` - List all aliases: @@ -30,7 +36,3 @@ - List all users on the system: `compgen -u` - -- Display help: - -`compgen --help` diff --git a/pages/common/complete.md b/pages/common/complete.md index 3b628b26341965..d1d211910969d4 100644 --- a/pages/common/complete.md +++ b/pages/common/complete.md @@ -1,16 +1,30 @@ # complete -> Get argument autocompletion to shell commands. +> Get and set argument autocompletion rules of shell commands in Bash. +> The specified completions will be invoked when `` is pressed in Bash. +> See also: `compgen`, `compopt`. > More information: . -- Apply a function that performs autocompletion to a command: +- Set arguments of a command to autocomplete through a function (completion response is sent in `COMPREPLY` variable): `complete -F {{function}} {{command}}` -- Apply a command that performs autocompletion to another command: +- Set arguments of a command to autocomplete through another command (`$1` is the command, `$2` is the argument the cursor is on, and `$3` is the argument preceding the cursor): `complete -C {{autocomplete_command}} {{command}}` +- Set arguments of a command to autocomplete to shell builtins: + +`complete -A builtin {{command}}` + - Apply autocompletion without appending a space to the completed word: `complete -o nospace -F {{function}} {{command}}` + +- List all loaded complete specifications: + +`complete -p` + +- List loaded complete specifications for a command: + +`complete -p {{command}}` diff --git a/pages/common/compopt.md b/pages/common/compopt.md index d76e6316e5e632..5365ceef34f01b 100644 --- a/pages/common/compopt.md +++ b/pages/common/compopt.md @@ -1,12 +1,22 @@ # compopt > Print or change the completion options for a command. -> More information: . +> `-o` means enabled and `+o` means disabled. +> See also: `compgen`, `complete`. +> More information: . + +- Print the completion options for given command: + +`compopt {{command}}` + +- Enable or disable a completion option of a command: + +`compopt {{-o|+o}} {{option1}} {{-o|+o}} {{option2}} {{command}}` - Print the options for the currently executing completion: `compopt` -- Print the completion options for given command: +- Enable or disable a completion option of a command: -`compopt {{command}}` +`compopt {{-o|+o}} {{option1}} {{-o|+o}} {{option2}}`