Artificial intelligent assistant

Restore default completion I use `compgen` when `$COMP_WORD` equals 1, now I want to restore default completion when otherwise, Right now I have, _rr() { case $COMP_CWORD in 1) COMPREPLY=($(compgen -W "A B" "${COMP_WORDS[$COMP_CWORD]}")) ;; esac } complete -F _rr rr Now when `$COMP_CWORD` is not 1, I got no completion for files / directories, that's the default completion I needed. Also I need to enable completion only when `${COMP_WORDS[$COMP_CWORD - 1]}` is `A` in this minimal case.

I'll assume that in your real-world case you want to do other things too, and so continue to use `case` constructs (although in this minimal case, `if` constructs would have been sufficient):


_rr()
{
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"

case "${COMP_CWORD}" in
1)
COMPREPLY=($(compgen -W "A B" "${cur}"))
;;
esac

case "${prev}" in
A)
COMPREPLY=($(compgen -f "${cur}"))
;;
esac
}

complete -F _rr rr


Documentation of the `-f` option to `compgen` is available in the Bash Reference Manual (scroll down to `file`, under the `-A action` subsection of the description of the `complete` builtin).

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 53ede91b149d5b3a176eef2a6463dfc9