Say I have a command named \"foo\" that takes one argument (either \"encrypt\" or \"decrypt\") and then a list of files. I want to write a bash completion script that helps wit
I know this is a little late, but I have found a solution here: https://stackoverflow.com/a/19062943/108105
Basically, you use complete -o bashdefault -o default
, and when you want to revert to the default bash completion you set COMPREPLY=()
. Here's an example:
complete -o bashdefault -o default -F _foo foo
_foo() {
local cur=${COMP_WORDS[COMP_CWORD]}
if (( $COMP_CWORD == 1 )); then
COMPREPLY=( $(compgen -W 'encrypt decrypt' -- "$cur") )
else
COMPREPLY=()
fi
}