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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 13 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

Your Answer

 
discard

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.