I have tested optcomplete
working with the optparse
module. Its example is a simple file so I could get that working. I also tested it using the argparse
module as the prior one is deprecated. But I really do not understand how and by whom the python program gets called on tab presses. I suspect bash
together with the shebang
line and the argparse
(or optparse
) module are involved in some way. I have been trying to figure this out (now gonna read the source code).
I have a little more complex program structure, which includes a wrapper around the piece of code which handles the arguments. Its argparse.ArgumentParser()
instantiation and calls to add_argument()
- which are superclassed into another intermediate module to avoid duplicating code, and wrapper around that is being called - are inside a function.
I want to understand the way this tab completion works between bash and python (or for that matter any other interpretor like perl
).
NOTE: I have a fair understanding of bash completion (which I learned just now), and I think I understand the bash(only) custom completion.
NOTE: I have read other similar SO questions, and none really answer this Q.
Edit: Here is the bash function.
I already understood how the python module gets to know about words typed in the command line, by reading os.environ
values of variables
$COMP_WORDS
$COMP_CWORD
$COMP_LINE
$COMP_POINT
$COMPREPLY
These variables have values only on tab press. My question is how does the python module gets triggered?