문제

I am trying to set up bash completion for a utility script I wrote, so I added the following script to /etc/bash_completion.d:

_mcd()
{
    local cur words
    COMPREPLY=()

    cur="${COMP_WORDS[COMP_CWORD]}"
    words=`mcd-completion-words`
    COMPREPLY=( $(compgen -W "${words}" -- "$cur") )
    return 0
}
complete -F _mcd mcd

The mcd-completion-words script programmatically finds available operators for the command. When I restart bash (or source the script), I can successfully tab complete, but if I do so, I can no longer backspace past a completed character.

Also, if I attempt to list all options (e.g. I attempt to tab complete w/ no word in place), bash adds a tab to the command, which I also cannot backspace.

How can I make bash mimic normal file completion behavior? Any help is appreciated. Thanks!


Here's a reduced testcase for mcd-completion-words that still exhibits the same behavior. Curiously, Dennis' case works for me as well (when substituting in words="one two three", for example).

#!/usr/bin/env php
<?php

print "one two three four five six seven eight nine";
도움이 되었습니까?

해결책

Here's a reduced test case; even an empty `php' command causes the erroneous completion behaviour:

$ _mcd() { php -r ""; COMPREPLY=( one ); }
$ complete -F _mcd mcd
$ mcd <TAB>            # Becomes 'mcd one' all right
$ mcd one <BACKSPACE>  # ERROR: doesn't work

This is on machine (Ubuntu) with both bash-3.2.48/bash-4.0.33 & php-5.2.6-3ubuntu4. On another machine (Debian) with bash-3.2.39 & php-5.2.6-1+lenny9, completion & backspace goes all right.

Using perl -e "" instead of php -r "" also goes all right.

Don't know what's going on, php conflicting with readline? Maybe you can try bug-bash mailing list?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top