Skip to content

complete, compgen, compopt: refresh pages #17638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 16, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pages/common/compgen.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# compgen

> A built-in command for auto-completion in Bash, which is called on pressing `<Tab>` 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: <https://www.gnu.org/software/bash/manual/bash.html#index-compgen>.

- 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:

Expand All @@ -30,7 +36,3 @@
- List all users on the system:

`compgen -u`

- Display help:

`compgen --help`
20 changes: 17 additions & 3 deletions pages/common/complete.md
Original file line number Diff line number Diff line change
@@ -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 `<Tab>` is pressed in Bash.
> See also: `compgen`, `compopt`.
> More information: <https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-complete>.

- 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}}`
16 changes: 13 additions & 3 deletions pages/common/compopt.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# compopt

> Print or change the completion options for a command.
> More information: <https://manned.org/compopt>.
> `-o` means enabled and `+o` means disabled.
> See also: `compgen`, `complete`.
> More information: <https://www.gnu.org/software/bash/manual/bash.html#index-compopt>.

- 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}}`