Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use tab completion more than typing letters. I used to type rm ~/De<TAB> and it would be completed to rm ~/Desktop/ so that I could continue on the next level.

Recently, that behaviour changed. The completion now yields rm ~/Desktop<SPACE>, which means I must backspace and type the slash if I want to continue. This makes me cry.

The changes seem to be located in the function _longopt() in /etc/bash_completion, however that is as far as I can follow. Is this change intentional, and if so, what is it good for? Can I have the old behaviour back, preferably by a config option instead of just copying the old code over from some other system?

Edit: The function for reference.

_longopt()
{
    local cur prev split=false
    _get_comp_words_by_ref -n = cur prev

    _split_longopt && split=true

    case "$prev" in
        --*[Dd][Ii][Rr]*)
            _filedir -d
            return 0
            ;;
        --*[Ff][Ii][Ll][Ee]*|--*[Pp][Aa][Tt][Hh]*)
            _filedir
            return 0
            ;;
    esac

    $split && return 0

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \
            sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}\).*/\1/p' | sort -u )" \
            -- "$cur" ) )
    elif [[ "$1" == @(mk|rm)dir ]]; then
        _filedir -d
    else
        _filedir
    fi
}
share|improve this question
    
The only way I could see that this would make sense is if ~/Desktop is a file or an empty directory. And in the second case, that's only useful for commands like rmdir, not for mkdir or touch. –  l0b0 May 10 '11 at 8:08
    
Could you post the body of your _longopt() function? –  Aleksandr Levchuk May 10 '11 at 8:58
    
@MPi: be aware that completion could depends on the command (first word of the command line). Also it can depends on readline settings (have you a ~/inputrc file?) and on the fact that the item is a real directory or a symlink to a directory. –  enzotib May 10 '11 at 9:24
    
Of course the completion depends on the first word of the line. Which is why I sometimes use a fantasy command to trick completion, and only change it to the real command before I send it. And I have no .inputrc on this system anymore. (Those were the days, fixing backspace and cursor keys…) And it happens for all elements, directory or file, symlink or not. –  MPi May 10 '11 at 11:11
1  
Excellent question, I've observed the exact same behaviour, and it annoys me. No idea about the reason, though. –  Christoph May 10 '11 at 11:14
show 1 more comment

3 Answers 3

up vote 22 down vote accepted

This is a known bug. See this LP question and these bugs 1 2.

This comment seems to be the fix. If you can't wait for a fix to trickle down the normal channels, edit /etc/bash_completion line 1587, change default to filenames (make a backup first).

share|improve this answer
3  
Summary: It is a bug, you can fix it locally until the patch arrives by editing /etc/bash_completion line 1587, change default to filenames. –  MPi May 10 '11 at 11:47
    
edited my anwer –  Christoph May 10 '11 at 11:57
add comment

I had the same problem and I fixed it by removing /etc/bash_completion.d/ directory, then reinstall bash_completion. I guess an old file was in this directory... Hopefully it will solve your problem too.

share|improve this answer
    
like this guy: timlabath.com/words/2011/05/10/… –  type May 18 '11 at 14:37
2  
This – indeed – fixed it. However, that method es much too radical, as it throws away many completions. After deleting the package bash-completion, one of the files remaining /etc/bash_completion.d/ must be the culprit. It was acroread.sh in my case – it redefines _filedir. –  MPi Jun 6 '11 at 12:58
add comment

I had, and solved, the same problem after installing Adobe Reader on Ubuntu 12.04.

I commented out the _filedir block in /etc/bash_completion.d/acroread.sh and it worked normally again.

share|improve this answer
    
As of today's date this is what worked for me as well. –  John Moeller Mar 26 '13 at 5:52
1  
Same here: acroread triggered it and commenting out the _filedir block (right on top) fixed it. You have to log out or run 'exec bash' in all your shells to see the effect, see this question. –  dirkjot Jun 14 '13 at 20:37
    
Thanks! its really helpful. –  anshuman Oct 22 '13 at 6:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.