Bash completion not working when environment variable defined

时间:2018-07-25 05:21:18

标签: bash tab-completion bash-completion

When I define an environment variable inline like this: env_variable=true command, my custom bash completion script fails. Example:

user@host in /tmp/tmp.6DRvQAkpFe
> ls
user@host in /tmp/tmp.6DRvQAkpFe
> docker-ssh 
container1 container2 container3 puppetmaster           
user@host in /tmp/tmp.6DRvQAkpFe
> VARIABLE=TEST docker-ssh 

The last command doesn't autocomplete like the one before it.

My bash completion function looks like this:

_docker-ssh() {
    local running=$(docker ps --format '{{.Names}}') 
    local cur prev opts base

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

    COMPREPLY=($(compgen -W "${running}" -- ${cur}))

    return 0
}

complete -F _docker-ssh docker-ssh

Is there something I'm missing in my COMPREPLY that would take into account environment variables?

1 个答案:

答案 0 :(得分:0)

您想要的行为是bash 4.3中的功能introduced

  

命令完成代码在查找要完成的命令名称单词之前会跳过空格和赋值语句。