Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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


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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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"`@'
share|improve this answer
Thanks again @Gilles, "sourcing" that file in Debian gives me immediately auto-completion for make –  nozimica Feb 21 '12 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. –  Stefan Müller Oct 7 '12 at 10:49

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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