FAQ

On Sat, May 22, 2010 at 11:01 AM, ntwrkd wrote:
I am trying to create a bash-style auto completion in a simple
command-line and script-based program i created using cmd.
I saw http://docs.python.org/library/rlcompleter.html, which I'm
thinking is the way to go for my program to intercept the tab key.
Would anyone have thoughts on this?

I wish cmd or cmd2 had this functionality built-in.
It is built in. Check the cmd documentation for complete_* method of Cmd class.

Following is an example of it use for a command called "open":

def complete_open(self, text, line, begidx, endidx):
asmfiles = glob('%s/*.asm' % ASMDIR)
matches = []
for path in asmfiles:
fname = os.path.basename(path)
if fname.startswith(text):
matches.append(fname)
return matches

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedMay 22, '10 at 6:01p
activeMay 22, '10 at 7:57p
posts2
users2
websitepython.org

2 users in discussion

Member thudfoo: 1 post Ntwrkd: 1 post

People

Translate

site design / logo © 2022 Grokbase