bash : simplify autocomplete.
This commit is contained in:
parent
53b143674f
commit
52c3c0b5e7
|
@ -1,13 +1,8 @@
|
||||||
# bash autocomplete.
|
# bash autocomplete.
|
||||||
# usage: complete -F _foo foo
|
# usage: _foo () { autocomplete "{foo,bar}" } ; complete -F _foo foo
|
||||||
# there are also options like -o nospace. see man for more info.
|
# there are also options like -o nospace. see man for more info.
|
||||||
|
# from man: The shell function function is executed in the current shell environment. When the function is executed, the first argument ($1) is the name of the command whose arguments are being completed, the second argument ($2) is the word being completed, and the third argument ($3) is the word preceding the word being completed on the current command line. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable.
|
||||||
autocomplete()
|
autocomplete()
|
||||||
{
|
{
|
||||||
local commands="$@"
|
COMPREPLY=( $(compgen -W "${@}") )
|
||||||
local cur prev
|
|
||||||
|
|
||||||
COMPREPLY=()
|
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
||||||
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue