9

I used to be able to type the following:

$> ./foo --arg=<TAB>

Where foo is any program I wrote, and it would give me a list of files in the current directory, just like tab-completion normally does. I didn't have to make any changes to /etc/bash_completion.

Recently, however, this has gone away for some unknown reason. Does anyone know how to re-enable this feature?

FWIW, this still does the correct thing (notice the lack of an equals sign):

$> ./foo --arg <TAB>

Javaxtreme
  • 313
  • 4
  • 9

3 Answers3

8

I removed all bash completion scripts and started adding them one by one to if any of them cause the problem.

In my case it turned out to be the npm completion script was the cause of this problem.

Not sure (yet) what the problem is, but this is the completion script which caused equal sign values not working as before:

    ###-begin-npm-completion-###
    #
    # npm command completion script
    #
    # Installation: npm completion >> ~/.bashrc  (or ~/.zshrc)
    # Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
    #

    COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
    COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
    export COMP_WORDBREAKS

    if type complete &>/dev/null; then
      _npm_completion () {
        local si="$IFS"
        IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
                               COMP_LINE="$COMP_LINE" \
                               COMP_POINT="$COMP_POINT" \
                               npm completion -- "${COMP_WORDS[@]}" \
                               2>/dev/null)) || return $?
        IFS="$si"
      }
      complete -F _npm_completion npm
    elif type compdef &>/dev/null; then
      _npm_completion() {
        si=$IFS
        compadd -- $(COMP_CWORD=$((CURRENT-1)) \
                     COMP_LINE=$BUFFER \
                     COMP_POINT=0 \
                     npm completion -- "${words[@]}" \
                     2>/dev/null)
        IFS=$si
      }
      compdef _npm_completion npm
    elif type compctl &>/dev/null; then
      _npm_completion () {
        local cword line point words si
        read -Ac words
        read -cn cword
        let cword-=1
        read -l line
        read -ln point
        si="$IFS"
        IFS=$'\n' reply=($(COMP_CWORD="$cword" \
                           COMP_LINE="$line" \
                           COMP_POINT="$point" \
                           npm completion -- "${words[@]}" \
                           2>/dev/null)) || return $?
        IFS="$si"
      }
      compctl -K _npm_completion npm
    fi
    ###-end-npm-completion-###
raphaëλ
  • 6,393
  • 2
  • 29
  • 35
  • 1
    See http://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-effecting-other-completion-script – user123444555621 Jul 29 '14 at 07:26
  • 1
    Yes they are modifying the COMP_WORDBREAKS variable. Thanks for pointing that out. That clarifies why this script breaks the behaviour of completion overall. I am entering an issue at npm. – raphaëλ Jul 29 '14 at 07:47
  • 1
    Great job! This was exactly the culprit. Really great job tracking this down. – Javaxtreme Sep 27 '14 at 08:27
  • 1
    Thank you!! This was driving me bonkers. – rusty May 15 '15 at 00:46
1

Not sure what environment you're in, but on a recent CentOS

complete -D -o default

enables filename completion after a token w/o whitespace as the default. To toggle it in the other direction:

complete -D -o nospace

However, it looks like older versions of the builtin don't have the -D option.

Bill West
  • 41
  • 2
  • My version of Linux (Ubuntu 12.04) does have the -D option, however complete -D -o default did not remedy the problem. – Javaxtreme Dec 04 '13 at 06:53
  • FWIW I can toggle the behavior on and off as described in an Ubuntu 12.04 vagrant. Does the behavior still happen in a sanitized bash? (e.g. `env -i bash --norc`) – Bill West Dec 04 '13 at 15:30
  • @Javaxtreme Have you been able to solve it. BTW i can confirm it works as expected in a sanitized bash. – raphaëλ May 09 '14 at 07:01
  • I was not able to solve the problem although as both you and @bill indicated, using a sanitized bash does work. My guess is there is some bash_completion module that is screwing it up, but I haven't been able to figure out which one. – Javaxtreme Jun 17 '14 at 08:52
  • Not exactly the answer to the question, but I was having the same problem and this solved it! Thanks @BillWest!! – deivid Nov 25 '15 at 21:14
1

I resolved the same trouble with Ubuntu 12.04 by using https://github.com/ai/rake-completion. You need to

  1. download the file wget -O ~/scripts/rake https://raw.githubusercontent.com/ai/rake-completion/master/rake
  2. add to your .bashrc: . ~/scripts/rake

or You can use one of other ways on that page.

Community
  • 1
  • 1
feech
  • 404
  • 4
  • 15