stecman / symfony-console-completion

Automatic tab-key completion for Symfony console application options, arguments and parameters
MIT License
420 stars 26 forks source link

Auto-completion on CentOS doesn't work #57

Closed aik099 closed 8 years ago

aik099 commented 8 years ago

I've tried to install auto-completion hook on CentOS, but upon TAB press I see TAB symbol added instead of actual command names of Symfony Console app.

GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Here are values of hook variables (I've typed program and pressed TAB TAB):

If I dump these vars on other computer, where auto-completion works, then values are exactly the same.

The result of _completion command dumped from hook also seems to be correct: new line separated command names.

I have no idea why Bash doesn't use it.

Video of how it works on Slackware (Bash 4.x): http://www.screencast.com/t/cpNRD7oVc Video of how it doesn't work on CentOS (Bash 3.x): http://www.screencast.com/t/sUMgB3j2x

stecman commented 8 years ago

Thanks, @aik099. Took a bit to figure this one out. Details are in the commit message, but the gist of it is that stdin gets taken over by the PHP subprocess for some reason on Centos (I was using 6.7 with BASH 4.1). The work around is specifying /dev/null as the stdin source for PHP.

# Basic completion function: works as expected
function _example_complete {
    local cur=${COMP_WORDS[COMP_CWORD]}
    local RESULT="apple banana cherry danger will robinson"
    COMPREPLY=( $(compgen -W '$RESULT' -- $cur) )
};

# Add a PHP process that does nothing
# Has the stdin take-over/tab characters showing issue
function _example_complete {
    php -r ''

    local cur=${COMP_WORDS[COMP_CWORD]}
    local RESULT="apple banana cherry danger will robinson"
    COMPREPLY=( $(compgen -W '$RESULT' -- $cur) )
};

# Give the PHP process /dev/null for stdin
# Works as expected
function _example_complete {
    php -r '' </dev/null

    local cur=${COMP_WORDS[COMP_CWORD]}
    local RESULT="apple banana cherry danger will robinson"
    COMPREPLY=( $(compgen -W '$RESULT' -- $cur) )
};
aik099 commented 8 years ago

Amazing. Thanks.

I've tested that this solution works for me as well.