'Returns the next completion for txt, or None if there is no completion'

def complete(self, txt):

    if (not self.lookup):
        if (not self._testing):
            self.lookup = []
            if (txt and (txt[0] in '~/')):
                path = os.path.expanduser(txt)
                if os.path.isdir(path):
                    files = glob.glob(os.path.join(path, '*'))
                    prefix = txt
                else:
                    files = glob.glob((path + '*'))
                    prefix = os.path.dirname(txt)
                prefix = (prefix.rstrip('/') or '/')
                for f in files:
                    if self.executable(f):
                        display = os.path.join(prefix, os.path.basename(f))
                        if os.path.isdir(f):
                            display += '/'
                        self.lookup.append((display, f))
            else:
                dirs = os.environ.get('PATH', self.DEFAULTPATH).split(':')
                for d in dirs:
                    try:
                        d = os.path.expanduser(d)
                        for cmd in glob.iglob(os.path.join(d, ('%s*' % txt))):
                            if self.executable(cmd):
                                self.lookup.append((os.path.basename(cmd), cmd))
                    except OSError:
                        pass
        self.lookup.sort()
        self.offset = (-1)
        self.lookup.append((txt, txt))
    self.offset += 1
    if (self.offset >= len(self.lookup)):
        self.offset = 0
    ret = self.lookup[self.offset]
    self.thisfinal = ret[1]
    return ret[0]
