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

7
  • There is no man page for set. Try help set (help is an internal BASH command) or man bash or info bash. Mar 31, 2015 at 11:52
  • What do type set and command set return in the shell? What do you get if you run set -x and then trigger this issue? Jul 7, 2015 at 22:21
  • type set says it's a bash built in. command set spits out all my environment variables and a ton of bash functions. set -x produces this regarding the error: + 23:set +o posix bash: 23:set: command not found Jul 8, 2015 at 0:42
  • @user1794469 my problem was related to an alias. try to remove yours and see if the problem persists. Jul 8, 2015 at 9:06
  • @EtanReisner your comment helped the most. would you post it as an answer to mark it solved ? Jul 8, 2015 at 9:09

3 Answers 3

14
+50

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

5
  • 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 8, 2015 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. Jul 8, 2015 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. Jul 8, 2015 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. Jul 8, 2015 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. Jul 8, 2015 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.

4
  • there is no make file in the /etc/bash_completion.d/ :( In /etc/bash_completion no sign of make entry either ... Nov 14, 2014 at 15:34
  • Then follow this advice: superuser.com/questions/142211/… Nov 14, 2014 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! Mar 30, 2015 at 8:55
  • 1
    The make completion file is in folder /usr/share/bash-completion/completions
    – Ebrahimi
    Oct 17, 2016 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 <(...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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