diff --git a/document/linux/config/bash/module/autocomplete.sh b/document/linux/config/bash/module/autocomplete.sh index e6cad74..1d4beed 100644 --- a/document/linux/config/bash/module/autocomplete.sh +++ b/document/linux/config/bash/module/autocomplete.sh @@ -1,13 +1,8 @@ # 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. +# 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() { - local commands="$@" - local cur prev - - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) - return 0 + COMPREPLY=( $(compgen -W "${@}") ) }