Makefile bash autocompletion issue with PHP generated targets

夙愿已清 提交于 2019-12-12 00:57:22

问题


In a large Makefile managed project, I recently added some PHP generated targets and bash completion stopped working: pressing [tab] does not trigger completion, but inserts a tab character.

I isolated the issue to this minimal Makefile:

# TARGETS = $(echo target1 target2)
TARGETS = $(php -r 'echo "target1 target2";')
# TARGETS = $(python -c 'print "target1 target2"')
# TARGETS = $(ruby -e 'puts "target1 target2"')

$(TARGETS):
    echo $@

If I use the bash-echo, python or ruby version of the TARGETS macro, bash completion works as expected, but if I use the php version bash completion becomes useless.

I can reproduce this issue on:

  • Mac OS 10.7.5 with default /usr/bin/php (5.3.15), default /bin/bash (3.2.48(1)-release), bash_completion 1.3_4 (installed with macports)
  • Ubuntu 10.04 with default /usr/bin/php (5.3.5-1ubuntu4ppa1), default /bin/bash (4.1.5(1)-release), default bash-completion 1:1.1-3ubuntu2

does anybody knows what is going wrong and what can be done about it?


回答1:


Ok, did some more researching and googling and found an explanation an workaround at:

  • Bash Completion Problems with option lists generated by PHP (May 2011; by Paul Serby)

Apparently the readline support in PHP (PHP CLI with libedit compiled in for readline support on Ubuntu Lucid) causes the issue in some way (not analyzed by Paul Serby) and the workaround is to explicitly take control of the standard input of the PHP process.

For example:

TARGETS = $(php -r 'echo "target1 target2";' < /dev/null )

or

TARGETS = $(echo '' | php -r 'echo "target1 target2";' )

both solutions work on both platforms I tried.

Further references:

  • Bug #53040 PHP crash/failure when called from bash-completion (bugs.php.net; reported Oct 2010)


来源:https://stackoverflow.com/questions/16233321/makefile-bash-autocompletion-issue-with-php-generated-targets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!