How to bash - full result of 2 approximate commands at the very same time

Here goes :

function _command() {
    local cur
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    if [ "$COMP_CWORD" -ge "2" ]; then
        COMPREPLY=($( compgen -W '$(pwd)' -- "$cur" ) )
    else
        COMPREPLY=($( compgen -W "arg1 arg2" -- "$cur" ) )
    fi
}
complete -F _command command

This functions well, as long as I source it.

What happens if I desire it to vehicle - full both results of pwd and also a few other approximate command, claim hostname? What happens if I additionally desired it to vehicle - full on any kind of documents course?

0
2019-12-02 02:50:39
Source Share
Answers: 1

Either

COMPREPLY=($(compgen -W '$(pwd)' -- "$cur") $(compgen -W '$(hostname)' -- "$cur"))

(you desire a larger array, simply make one) or

COMPREPLY=($( compgen -W '$(pwd; hostname)' -- "$cur" ) )

(still autocompleting one command).

0
2019-12-03 04:12:25
Source