cmd, readline, and /path/filename completion

Michael Gilfix mgilfix at eecs.tufts.edu
Thu Jul 25 09:42:52 EDT 2002


  Ah. Was just trying to be helpful :) Glad you solved it though.  It
can be hard to say what methods you need to override as different
implementations expose them differently. I hadn't personally messed
with the python one. Perhaps you could submit this to a python
cookbook or something. I'm sure others would find it really useful.

                  -- Mike

On Thu, Jul 25 @ 05:44, Dave Cinege wrote:
> On Thursday 25 July 2002 0:40, Dave Cinege wrote:
> 
> > I'm by no means a coding novice, and I already know I (or somewhere in
> > readline) must walk the path and gather a list of executable files. Where
> > I'm lost is how to pass this to readline. (Or activate it in readline)
> 
> Just needed to do more homework. The thing to do in my situation
> is to override the 'completenames' method of cmd. The method below
> completes all executeables in the path just like bash.
> 
> What confused the hell out of me is I couldn't get 'completedefault'
> to do anything. Viewing the cmd modules showed that is only
> run when the completer index is > 0. Thus, 'commands' (the beginning of
> a line) is run against completenames... 
> 
> def completenames(self, text, line, begidx, endidx):
> 	l = cmd.Cmd.completenames(self, text, line, begidx, endidx)
> 	path = os.environ['PATH'].split(':')
> 	textlen = len(text)
> 	for dir in path:
> 		try:
> 			files = os.listdir(dir)
> 		except:
> 			continue
> 		for file in files:
> 			if textlen > 0 and file[:textlen] != text:
> 				continue
> 			if os.access(dir+'/'+file, os.X_OK):
> 				l += [file]
> 	return l
> 
> 
> 
> -- 
> The time is now 22:48 (Totalitarian)  -  http://www.ccops.org/
`-> (dcinege)

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html




More information about the Python-list mailing list