LinuxCommandLibrary

complete

TLDR

Complete with files

$ complete -f [command]
copy
Complete with directories
$ complete -d [command]
copy
Complete with word list
$ complete -W '[start stop restart]' [myservice]
copy
Complete using function
$ complete -F [_my_completion] [mycommand]
copy
Remove completion
$ complete -r [command]
copy
List all completions
$ complete -p
copy
Complete with no space after
$ complete -o nospace -W '[opt1 opt2]' [command]
copy

SYNOPSIS

complete [options] [name...]

DESCRIPTION

complete specifies how arguments for commands should be completed. Bash builtin for programmable completion. Defines completion specifications (compspecs) for commands.

PARAMETERS

-a

Complete with aliases
-b
Complete with builtins
-c
Complete with commands
-d
Complete with directories
-f
Complete with files
-g
Complete with groups
-j
Complete with jobs
-k
Complete with keywords
-s
Complete with services
-u
Complete with users
-v
Complete with variables
-A action
Use action for completion
-W wordlist
Complete from wordlist
-F function
Call shell function
-C command
Run command for completions
-G pattern
Glob pattern for files
-X pattern
Filter out matches
-P prefix
Add prefix to results
-S suffix
Add suffix to results
-p
Print current completions
-r
Remove completion spec

COMP-OPTIONS (-o)

filenames: Treat as filenames (add slashes, quote)
nospace: Don't append space after completion
nosort: Don't sort alphabetically
bashdefault: Fall back to bash defaults
default: Fall back to readline defaults

CAVEATS

Bash builtin only. Completions stored per-session. Use /etc/bash_completion.d/ for persistent completions.

SEE ALSO

compgen(1), bash(1)

Copied to clipboard