On Sat, May 22, 2010 at 11:01 AM, ntwrkd <ntw...@gmail.com> 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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to