Search code examples
pythonautocompletecmdcode-completion

Cmd module : having completion on the first word


I use completedefault (see the doc) for completion with Cmd module. But it seems to be called only after the first word.

def completedefault(self,text,line,begidx,endidx):                                          
     print('completedefault is called')                                                      
     return ['foo','bar']

Output :

(Cmd) f<Tab><Tab>
(Cmd) foo f<Tab><Tab>
completedefault is called
foo bar

How to change this behavior to have it called even on the first word ?


Solution

  • The answer is actually simple : Cmd.completenames. More info here. A similar question here.