Broken tab completion on make under linux

2.9k views Asked by At

I have no idea how tab completion works, but all of a sudden mine is broken. I don't even know what info to provide other than the use case. there is a target clean in the makefile.

$ make c<tab> results in

$ make c23:set: command not found lean

EDIT: I believe somehow I ruined the set bash built-in since man set says No manual entry for set and which set doesn't report anything. Invoking set on the terminal, however, produces result.

I'm using: GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) and GNU Make 3.81

3

There are 3 answers

5
Ciprian Tomoiagă On BEST ANSWER

thanks to Etan's comment and Aaron's indication of where makefiles are, I managed to debug this.

I ran set -x so I could track what was happening when doing the tab completion. The output of make c<tab> consists mostly of commands from the bash completion file for make, located at /usr/share/bash-completion/completions/make (1). However, I noticed the an inconsistency between the output and the file. Towards the end, the output said:

+ local mode=--
+ ((  COMP_TYPE != 9  ))
++ set +o
++ grep --colour=auto -n -F posix
+ local 'reset=23:set +o posix'
+ set +o posix

Which I identified as corresponding to these lines from the file:

if (( COMP_TYPE != 9 )); then
    mode=-d # display-only mode
fi

local reset=$( set +o | grep -F posix ); set +o posix # for <(...)

So the output did a grep --colour=auto -n instead of just grep. Indeed, I had setup this alias for grep

Make worked as soon as I removed the alias.

I hope this helps others debug their problems.

EDIT: I have submitted a bug report here: https://alioth.debian.org/tracker/index.php?func=detail&aid=315108&group_id=100114&atid=413095

4
Aaron Digulla On

Look into /etc/bash_completion, /etc/bash_completion.d and/or /usr/share/bash-completion/completions. You should find a file make which contains the script that will be called when press Tab.

Use the packaging system of your Linux distro to validate the file (or maybe revert to an older version).

Another cause of this could be something in the Makefile which throws the parser in the BASH completion script off the track.

0
Pacheco On

Not trying to get any credits here, but the best solution is actually a bit hidden in the comments... Please vote this comment up instead of my answer!

easy steps to fix this:

sudo vi /usr/share/bash-completion/completions/make

find the line that has the grep instruction. It should look like this:

local reset=$( set +o | grep -F posix ); set +o posix # for <(...)

add a "\" before the "grep" instruction:

local reset=$( set +o | \grep -F posix ); set +o posix # for <(...)