Artificial intelligent assistant

How to avoid duplicate completion in Bash I defined the basic completion script. For program d, it can take subcommand exempt, limit, show, and update. complete -W "exempt limit show update" d However, when I press tab after `d exempt`, bash displays the completion menu again. $ d <tab> exempt limit show update $ d exempt <tab> exempt limit show update $ d exempt exempt <tab> exempt limit show update How do I prevent Bash from inserting the same word again and again?

What you see is the intended behavior when you use the basic completion mechanism `complete -W`.

If you want a more intelligent completion, you need to to write completion functions (see the "Programmable Completion" section in the Bash manual) and use `complete -F`.

Here is how to adapt your example:


$ comp_d() {
COMPREPLY=( $(
if [ "$COMP_CWORD" -eq 1 ]; then
compgen -W "exempt limit show update" "$2"
fi
) )
}

$ complete -F comp_d d


Such functions must return the completion candidates in an array `COMPREPLY`. I only use your word list when the user is completing the first argument (`COMP_CWORD` is 1), else the array is left empty.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 9b18c44f9b4bf686959923f6cb3560d5