Makefile variable autocompletion in bash -


let's makefile like:

dir :=#  foobar:     ls ${dir} 

when type

mak[tab] f[tab] 

it gives correctly

make foobar 

but

make foobar d[tab] 

doesn't magic

make foobar dir= 

so question is: there way autocomplete makefile variables (aside targets) in bash?

this answer far complete. grep variables in makefile use make -p print makefile database:

# gnu make 3.81 # copyright (c) 2006  free software foundation, inc. # free software; see source copying conditions. # there no warranty; not merchantability or fitness # particular purpose.  # program built x86_64-pc-linux-gnu  # make data base, printed on mon oct 13 13:36:12 2014  # variables  # automatic <d = $(patsubst %/,%,$(dir $<)) # automatic ?f = $(notdir $?) # environment desktop_session = kde-plasma # ... # makefile (from `makefile', line 1) dir :=  

we looking lines starting # makefile (from 'makefile', line xy) , extract name of following variable:

$ make -p | sed -n '/# makefile (from/ {n; p;}' makefile_list :=  makefile dir := 

in next step remove variable name (everything after :=):

$ make -p makefile | sed -n '/# makefile (from/ {n; s/^\([^.#:= ]\+\) *:\?=.*$/\1/p;}' makefile_list dir 

the following lines demonstrate how done:

_make_variables() {   # current completion   local cur=${comp_words[comp_cword]}   # list of possible makefile variables   local var=$(make -p makefile | sed -n '/# makefile (from/ {n; s/^\([^.#:= ]\+\) *:\?=.*$/\1=/p;}')   # don't add space after completion   compopt -o nospace    # find possible matches   compreply=( $(compgen -w "${var}" -- ${cur}) ) }  # use _make_variables complete make arguments complete -f _make_variables make 

now make d[tab] results in make dir=.

sadly loose file , target completion approach. useful remove more variables (e.g. makefile_list) completion output.

maybe worth fill wish/bug report against bash-completion project add feature.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -