Take the 2-minute tour ×
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.

This question already has an answer here:

Is there a way to have bash know exactly what to display when you double tab? For example I have a python script scpy which requires a couple arguments. For example like apt-get, if you double tab gives you

autoclean        build-dep        clean            dselect-upgrade  purge            source           upgrade
autoremove       check            dist-upgrade     install          remove           update  

Is there a way to do that for your own scripts/programs? Do I need to wrap my python script in a bash script?

share|improve this question

marked as duplicate by jasonwryan, rahmu, Thor, Michael Mrozek Feb 15 '13 at 20:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

up vote 11 down vote accepted

The easiest way of doing this is to include a shell script in /etc/bash_completion.d/. The basic structure of this file is a simple function that performs the completion and then invocation of complete which is a bash builtin. Rather than go into detail on how to use complete, I suggest you read An Introduction to Bash Completion. Part 1 covers the basics and Part 2 gets into how you would go about writing a completion script.

A denser description of bash completion can be found in the "Programmable Completion" section of man bash (you can type "/Programmable Completion" and then press 'n' a few times to get there quickly. Or, if you are feeling luck, "g 2140 RETURN").

share|improve this answer
    
Thanks. That's exactly what I was looking for. –  Falmarri Sep 9 '10 at 4:09
add comment

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