0

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?

2
  • 1
    I cannot reproduce this issue in any way. Use set -x inside the function to check the actual values. Commented Jul 25, 2018 at 9:06
  • I can't reproduce it either. As a side note, you don't need your function, you can reduce the second code block to complete -W '$(docker ps --format "{{.Names}}")' docker-ssh. Commented Jul 25, 2018 at 14:25

1 Answer 1

0

The behavior you want is a feature introduced in bash 4.3.

The command completion code skips whitespace and assignment statements before looking for the command name word to be completed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.