Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broken tab completion on make under linux

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

like image 248
Ciprian Tomoiagă Avatar asked Nov 14 '14 14:11

Ciprian Tomoiagă


People also ask

What is tab completion in Linux?

Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands.

Does bash have tab completion?

Bourne shell and csh do not, but ksh, bash, tcsh, and zsh all have tab completion to varying degrees. The basic principle in all of these shells is the same; you type the start of the word, hit the <TAB> key twice, and the list of possible commands or files is displayed.

How do I know if bash-completion is installed?

Depending on your package manager, you have to manually source this file in your ~/. bashrc file. Reload your shell and verify that bash-completion is correctly installed by typing type _init_completion .


2 Answers

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

like image 84
Ciprian Tomoiagă Avatar answered Oct 18 '22 07:10

Ciprian Tomoiagă


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.

like image 2
Aaron Digulla Avatar answered Oct 18 '22 05:10

Aaron Digulla