4

I'm using tcsh in a SUSE 11 box and I realized that when typing

makeTab

it allows me to auto-complete the rules available within the Makefile, not the files that are inside the current directory.

I've tested this with RedHat and Ubuntu at work and Debian at home (all with tcsh), and none of them supports this (IMO) nice behavior.

How can this be achieved with the other distributions as well?
This is something I've wanted to have since many years ago.

2 Answers 2

2

You need to add calls to complete to your shell startup file (~/.tcshrc). Apparently your SuSE box has predefined rules for make; look for them in /etc/csh.cshrc or some other file provided alongside tcsh (rpm -ql tcsh).

The tcsh distribution comes with some example completions (Debian puts them in /usr/share/doc/tcsh/examples/complete.tcsh.gz); here's the one for make:

complete make \
    'n/-f/f/' \
    'c/*=/f/' \
    'n@*@`cat -s GNUmakefile Makefile makefile |& sed -n -e "/No such file/d" -e "/^[^     #].*:/s/:.*//p"`@'
2
  • Thanks again @Gilles, "sourcing" that file in Debian gives me immediately auto-completion for make
    – nozimica
    Feb 21, 2012 at 22:54
  • I tried this under Mac OS but get the following result: make `cat -s GNUmakefile Makefile makefile |& sed -n -e "/No such file/d" -e "/^[^ #].*:/s/:.*//p"`: No match. Oct 7, 2012 at 10:49
1

Using this answer on StackOverflow to use make itself to calculate all the available targets and merging this into the Debian example script as shown in the other answer here and then adding some more, this yields:

alias complete_make_target_filter 'awk -F: '"'"'/^[a-zA-Z0-9][^\$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'"'"

complete make \
    'n/--assume-old/f/' \
    'n/--assume-new/f/' \
    'n/--directory/d/' \
    'n/--file/f/' \
    'n/--include-dir/d/' \
    'n/--makefile/f/' \
    'n/--new-file/f/' \
    'n/--old-file/f/' \
    'n/--what-if/f/' \
    'n/-d/d/' \
    'n/-f/f/' \
    'c/*=/f/' \
    'n@*@`make -qp  |& grep -v Stop |complete_make_target_filter|xargs echo --always-make --directory -d --debug -e --environment-overrides --file --makefile -i --ignore-errors -I --include-dir -j --jobs -k --keep-going -l --load-average --max-load -L --check-symlink-times -n --just-print --dry-run --recon -o --old-file --assume-old -p --print-database -q --question -r --no-builtin-rules -R --no-builtin-variables -s --silent --quiet -S --no-keep-going --stop -t --touch -v --version -w --print-directory --no-print-directory -W --what-if --new-file --assume-new --warn-undefined-variables`@'

Put this along with other nifty completion scripts into a ~/.complete/ directory and then source them all in your ~/.cshrc and you're all set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .