8

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

Ciprian Tomoiagă
  • 3,773
  • 4
  • 41
  • 65

3 Answers3

14

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

Community
  • 1
  • 1
Ciprian Tomoiagă
  • 3,773
  • 4
  • 41
  • 65
  • 6
    isn't this almost a bug ? I mean this script should use /usr/bin/grep instead of relying on potential user aliases? Anyway thanks for the solution, I also had the same alias in my bashrc file. – claf Jul 08 '15 at 10:49
  • 2
    Indeed, being broken by user aliases is a somewhat serious flaw in this completion script. It should be using a variety of things to prevent that from happening. – Etan Reisner Jul 08 '15 at 13:25
  • 4
    this seems like a bug to me, someone should report it. I think that adding color to grep is a common enough alias too... it's a one character fix to simply use `\grep` in the scrirpt. I added that to my `/usr/share/bash-completion/completions/make` and it was fixed. Can i split the bounty? Half should go to @etan-reisner and half to @ciprian-tomoiaga. – user1794469 Jul 08 '15 at 13:44
  • 2
    It is certainly a bug and should be reported. But color wasn't the problem (auto won't trigger there) the `-n` was. – Etan Reisner Jul 08 '15 at 13:47
  • @user1794469 Like I said in my comment on the post (I didn't realize someone else has posted the bounty) just accept and award this answer. – Etan Reisner Jul 08 '15 at 13:48
2

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • there is no `make` file in the `/etc/bash_completion.d/` :( In `/etc/bash_completion` no sign of `make` entry either ... – Ciprian Tomoiagă Nov 14 '14 at 15:34
  • Then follow this advice: http://superuser.com/questions/142211/bash-completion-processing-gone-bad-how-to-debug – Aaron Digulla Nov 14 '14 at 15:42
  • sorry to respawn this, but I still couldn't fix it. I lived with it for a few months, but now I'd really need it. Also, I don't think it's the Makefile, since it happens even with the most basic Makefile. Also, can you see my edit, please? Thanks! – Ciprian Tomoiagă Mar 30 '15 at 08:55
  • 1
    The `make` completion file is in folder `/usr/share/bash-completion/completions` – Ebrahimi Oct 17 '16 at 10:46
1

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 <(...)
Pacheco
  • 133
  • 7