0

I'm writing a simple script to autocomplete when I press TAB.

The php script contains a simple "echo".

In this case, the autocomplete works but a "tab" is appended to the output making it useless

Code from the script

scriptPath='/home/hassen/workspace/scripts/bin/test.php'

_dda()
{
    local cur
    COMPREPLY=()
    unset COMP_WORDS[0] #remove "j" from the array
    cur=${COMP_WORDS[*]}
    IFS=$'\n\n' read -d '' -a COMPREPLY < <($scriptPath --completion "$cur")
    return 0
}
complete -F _dda dda

alias dda=$scriptPath

Code from php script

<?php
echo "hello";
?>

Here is the annoying part: If I print the echo in Python or Ruby, it works like a charm -- ie each time I press TAB, it calls the scripts and output hello.

Is this a bug with PHP or my code? They seem to disagree at http://bugs.php.net/bug.php?id=52755

hbt
  • 1,011
  • 3
  • 16
  • 28
  • PHP doesn't seems fine to run in command-line. It has missing the #!/usr/bin/php5 part. – fabrik Sep 01 '10 at 11:33
  • @fabrik Even if I had that, it doesn't help. I can call the script using ./test.php or php test.php -- both producing `hello` – hbt Sep 01 '10 at 17:29

4 Answers4

1

CLIFramework provides a command helps you generate the bash completion script by your command definitions, so you don't have to write the completion script by hands:

https://github.com/c9s/CLIFramework

The screencast:

enter image description here

p.s. it also works for zsh

c9s
  • 1,888
  • 19
  • 15
1

It works as desired here, are you very sure the PHP file itself doesn't hold a tab, possibly after the ?>?

Versions: PHP 5.3.2, GNU bash version 4.1.5

Wrikken
  • 69,272
  • 8
  • 97
  • 136
0

I had the same issue, not directly with a custom bash completion, but through Makefile bash completion.

Workaround at Makefile bash autocompletion issue with PHP generated targets

Community
  • 1
  • 1
Stefaan
  • 4,696
  • 3
  • 23
  • 16
0

There is a known problem in PHP that is documented here that prevents this from working. https://bugs.php.net/bug.php?id=53040

Use /usr/bin/php-cgi instead of /usr/bin/php for running the script and it should work.

Pablo López Torres
  • 1,083
  • 1
  • 8
  • 14