Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TAB autocomplete python CLI

I was just wondering if it is possible to write a Python script that is run in the shell that can provide suggestions to the user when they hit Tab?

for example, how certain applications can limit the file types suggested by what they support. I haven't found anything in optParse that does this?

Ideally it would be:

myScript.py [TAB] (shell prints list of options)

Any suggestions? Specifically using KDE under OpenSuse and tcsh

Much appreciated

like image 780
Dhruv Govil Avatar asked Nov 27 '12 02:11

Dhruv Govil


2 Answers

That is a feature of the shell, not of the Python script being called. See this question on SO for more info on shell completion. In particular, you're looking for programmable completion.

like image 100
Florian Brucker Avatar answered Oct 09 '22 06:10

Florian Brucker


I think you're looking for something like optcomplete. It implements a completion module for bash that will autocomplete the options for any Python program that uses optparse. You could take hints from that and convert it to what you need.

like image 29
Noufal Ibrahim Avatar answered Oct 09 '22 06:10

Noufal Ibrahim