Python readline.get_line_buffer() Examples

The following are 30 code examples of readline.get_line_buffer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module readline , or try the search function .
Example #1
Source File: autocomplete.py    From vault with MIT License 6 votes vote down vote up
def autocomplete(text, state):
    """ Generic readline completion entry point. """

    buffer = readline.get_line_buffer()

    comp = completion_list
    if not is_case_sensitive:
        buffer = buffer.lower()
        comp = [c.lower() for c in completion_list]

    results = [c for c in comp if c.startswith(buffer)] + [None]

    # Handle multi-word inputs by truncating strings at the last space
    if buffer.find(' ') > 0:
        strip_pos = buffer.rfind(' ') + 1
        results = [i[strip_pos:] for i in results if i is not None] + [None]

    return results[state] 
Example #2
Source File: cli.py    From pytgbot with GNU General Public License v3.0 6 votes vote down vote up
def print(self, text):
        current_input = readline.get_line_buffer()
        delete_chars = len(self.query) + len(current_input)

        # remove the input:
        sys.stdout.flush()
        for i in range(delete_chars):
            sys.stdout.write("\b \b")
        # end for
        sys.stdout.write("\033[K")
        sys.stdout.flush()

        # actual output
        sys.stdout.write(str(text))
        sys.stdout.write("\n")
        sys.stdout.flush()
        # load back the input
        sys.stdout.write(self.query)
        sys.stdout.flush()
        sys.stdout.write(current_input)
        sys.stdout.flush()
        readline.redisplay()
    # end def 
Example #3
Source File: autocomplete.py    From uac-a-mola with GNU General Public License v3.0 6 votes vote down vote up
def complete(self, text, state):
        "Generic readline completion entry point."
        buffer = readline.get_line_buffer()
        line = readline.get_line_buffer().split()
        # show all commands
        if not line:
            return [c + ' ' for c in self.commands][state]
        # account for last argument ending in a space
        if RE_SPACE.match(buffer):
            line.append('')
        # resolve command to the implementation function
        cmd = line[0].strip()
        if cmd in self.commands:
            impl = getattr(self, 'complete_%s' % cmd)
            args = line[1:]
            if args:
                return (impl(args) + [None])[state]
            return [cmd + ' '][state]
        results = [c + ' ' for c in self.commands if c.startswith(cmd)] + [None]
        return results[state] 
Example #4
Source File: autocomplete.py    From ibombshell with GNU General Public License v3.0 6 votes vote down vote up
def complete(self, text, state):
        "Generic readline completion entry point."
        buffer = readline.get_line_buffer()
        line = readline.get_line_buffer().split()
        # show all commands
        if not line:
            return [c + ' ' for c in self.commands][state]
        # account for last argument ending in a space
        if RE_SPACE.match(buffer):
            line.append('')
        # resolve command to the implementation function
        cmd = line[0].strip()
        if cmd in self.commands:
            impl = getattr(self, 'complete_%s' % cmd)
            args = line[1:]
            if args:
                return (impl(args) + [None])[state]
            return [cmd + ' '][state]
        results = [c + ' ' for c in self.commands if c.startswith(cmd)] + [None]
        return results[state] 
Example #5
Source File: autocomplete.py    From BoomER with GNU General Public License v3.0 6 votes vote down vote up
def complete(self, text, state):
        buffer = readline.get_line_buffer()
        line = buffer.split()

        if not line:
            return [cmd + ' ' for cmd in self.COMMANDS][state]

        EXPR = re.compile('.*\s+$', re.M)

        if EXPR.match(buffer):
            line.append('')

        command = line[0].strip()

        if command in self.COMMANDS:
            command_function = getattr(self, 'complete_%s' % command)
            args = line[1:]
            if args:
                return (command_function(args) + [None])[state]
            return [command + ' '][state]
        results = [cmd + ' ' for cmd in self.COMMANDS if cmd.startswith(command)] + [None]

        return results[state] 
Example #6
Source File: Interface.py    From smod-1 with GNU General Public License v2.0 6 votes vote down vote up
def complete(self, text, state):
        
        	buffer = readline.get_line_buffer()
        	line = readline.get_line_buffer().split()
        
        	if self.RE_SPACE.match(buffer):
            		line.append('')
        
        	cmd = line[0].strip()
        	if cmd in Command.COMMANDS:
            		impl = getattr(self, 'complete_%s' % cmd)
            		args = line[1:]
            		if args:
                		return (impl(args) + [None])[state]
            		return [cmd + ' '][state]
        	results = [c + ' ' for c in Command.COMMANDS if c.startswith(cmd)] + [None]
        	return results[state] 
Example #7
Source File: armory_interactive.py    From armory with GNU General Public License v3.0 6 votes vote down vote up
def complete(self, text, state):

        if state == 0:  # on first trigger, build possible matches

            full_cmd = readline.get_line_buffer()
            if full_cmd.startswith("set "):
                if full_cmd.count(" ") == 1:
                    self.matches = [
                        s for s in self.module_options if s and s.startswith(text)
                    ]
                else:
                    # print("\n%s\n%s" % (full_cmd, text))
                    self.matches = [s for s in glob.glob(full_cmd.split(" ")[-1] + "*")]
            elif text:  # cache matches (entries that start with entered text)

                self.matches = [s for s in self.options if s and s.startswith(text)]
            else:  # no text entered, all matches possible
                self.matches = self.options[:]

        # return match indexed by state
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #8
Source File: armory_interactive.py    From armory with GNU General Public License v3.0 6 votes vote down vote up
def complete(self, text, state):

        if state == 0:  # on first trigger, build possible matches

            if readline.get_line_buffer().startswith("use_module "):

                self.matches = [s for s in self.modules if s and s.startswith(text)]
            elif readline.get_line_buffer().startswith("use_report "):

                self.matches = [s for s in self.reports if s and s.startswith(text)]
            elif text:  # cache matches (entries that start with entered text)

                self.matches = [s for s in self.options if s and s.startswith(text)]
            else:  # no text entered, all matches possible
                self.matches = self.options[:]

        # return match indexed by state
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #9
Source File: completer.py    From autolab_core with Apache License 2.0 6 votes vote down vote up
def complete(self, text, state):
        "Generic readline completion entry point."

        # dexnet entity tab completion
        results = [w for w in self.words if w.startswith(text)] + [None]
        if results != [None]:
            return results[state]

        buffer = readline.get_line_buffer()
        line = readline.get_line_buffer().split()

        # dexnet entity tab completion
        results =  [w for w in self.words if w.startswith(text)] + [None]
        if results != [None]:
            return results[state]

        # account for last argument ending in a space
        if RE_SPACE.match(buffer):
            line.append('')

        return (self.complete_extra(line) + [None])[state]

    # dexnet entity tab completion 
Example #10
Source File: dexnet_cli.py    From PointNetGPD with MIT License 6 votes vote down vote up
def complete(self, text, state):
        "Generic readline completion entry point."

        # dexnet entity tab completion
        results = [w for w in self.words if w.startswith(text)] + [None]
        if results != [None]:
            return results[state]

        buffer = readline.get_line_buffer()
        line = readline.get_line_buffer().split()

        # dexnet entity tab completion
        results = [w for w in self.words if w.startswith(text)] + [None]
        if results != [None]:
            return results[state]

        # account for last argument ending in a space
        if RE_SPACE.match(buffer):
            line.append('')

        return (self.complete_extra(line) + [None])[state]

    # dexnet entity tab completion 
Example #11
Source File: asadm.py    From aerospike-admin with Apache License 2.0 6 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        try:
            if state >= 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                compfunc = self.completenames
                self.completion_matches = compfunc(text, line, begidx, endidx)
        except Exception:
            pass

        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #12
Source File: defs.py    From hadrian with Apache License 2.0 6 votes vote down vote up
def complete(self, text, state):
        """:type text: string
        :param text: partial text to complete
        :type state: integer
        :param state: the number of times the user has pressed tab. If ``0``, generate a new list of candidates; otherwise, use the old one
        :rtype: list of strings
        :return: set of completions
        """

        if state == 0:
            line = readline.get_line_buffer()
            begin = readline.get_begidx()
            end = readline.get_endidx()
            established = line[:begin]
            active = line[begin:end]
            self.candidates = self.mode.complete(established, active)
        try:
            return self.candidates[state]
        except IndexError:
            return None 
Example #13
Source File: cmd.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #14
Source File: shell.py    From magnitude with MIT License 5 votes vote down vote up
def complete(self, token, state):
        """Return a possible completion for readline

        This function is called with state starting at zero to get the
        first completion, then one/two/three etc until you return None.  The best
        implementation is to generate the list when state==0, save it,
        and provide members on each increase.

        The default implementation extracts the current full input
        from readline and then calls :meth:`complete_command` or
        :meth:`complete_sql` as appropriate saving the results for
        subsequent calls.
        """
        if state==0:
            import readline
            # the whole line
            line=readline.get_line_buffer()
            # beginning and end(+1) of the token in line
            beg=readline.get_begidx()
            end=readline.get_endidx()
            # Are we matching a command?
            try:
                if self._completion_first and line.startswith("."):
                    self.completions=self.complete_command(line, token, beg, end)
                else:
                    self.completions=self.complete_sql(line, token, beg, end)
            except:
                # Readline swallows any exceptions we raise.  We
                # shouldn't be raising any so this is to catch that
                import traceback; traceback.print_exc()
                raise

        if state>len(self.completions):
            return None
        return self.completions[state]

    # Taken from https://sqlite.org/lang_keywords.html 
Example #15
Source File: cmd.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #16
Source File: display.py    From nekoatsume with GNU Affero General Public License v3.0 5 votes vote down vote up
def complete(self, action, index):
        buf = readline.get_line_buffer()
        if index == 0:
            if buf != "":
                self.matches = [a for a in self.actions if a.startswith(buf)]
            else:
                self.matches = self.actions[:]
        response = self.matches[index]
        if response:
            if action != buf:
                response = response[len(buf)-len(action):]
            return response 
Example #17
Source File: interpreter.py    From isf with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            original_line = readline.get_line_buffer()
            line = original_line.lstrip()
            stripped = len(original_line) - len(line)
            start_index = readline.get_begidx() - stripped
            end_index = readline.get_endidx() - stripped

            if start_index > 0:
                cmd, args = self.parse_line(line)
                if cmd == '':
                    complete_function = self.default_completer
                else:
                    try:
                        complete_function = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        complete_function = self.default_completer
            else:
                complete_function = self.raw_command_completer

            self.completion_matches = complete_function(text, line, start_index, end_index)

        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #18
Source File: cmd.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #19
Source File: interactive.py    From rainbowstream with MIT License 5 votes vote down vote up
def complete(self, text, state):
        """
        Complete
        """
        response = None
        if state == 0:
            origline = readline.get_line_buffer()
            begin = readline.get_begidx()
            end = readline.get_endidx()
            being_completed = origline[begin:end]
            words = origline.split()

            if not words:
                self.current_candidates = sorted([c for c in self.options])
            else:
                try:
                    if begin == 0:
                        candidates = [c for c in self.options]
                    elif words[-1] in self.options[words[0]]:
                        candidates = []
                    else:
                        first = words[0]
                        candidates = self.options[first]

                    if being_completed:
                        self.current_candidates = [w for w in candidates
                                                   if w.startswith(being_completed)]
                    else:
                        self.current_candidates = candidates

                except (KeyError, IndexError):
                    self.current_candidates = []

        try:
            response = self.current_candidates[state]
        except IndexError:
            response = None
        return response 
Example #20
Source File: tick.py    From thetick with GNU Lesser General Public License v3.0 5 votes vote down vote up
def notify_new_bot(self, listener, bot):

        # Notifications for reconnecting bots are skipped because they're
        # not very useful except for debugging.
        if bot.uuid not in self.known_bots:

            # Prepare the notification text.
            index = listener.bots.keys().index(bot.uuid)
            text = "Bot %d [%s] connected from %s" % (index, bot.uuid, bot.from_addr[0])
            text = Fore.BLUE + Style.BRIGHT + text + Style.RESET_ALL

            # If the main thread is blocked waiting at the prompt,
            # do some ANSI escape codes magic to insert the notification text on screen.
            # Note that we cannot use this trick if --no-color was specified.
            # (I mean, we could, but what if the reason the colors were turned off
            # was that the C&C was not being run in a console with a proper tty?)
            if self.inside_prompt and ANSI_ENABLED:
                buf_bkp = readline.get_line_buffer()
                sys.stdout.write("\033[s\033[0G\033[2K" + text + "\n")
                sys.stdout.write(self.prompt.replace("\x01", "").replace("\x02", "") + buf_bkp + "\033[u\033[1B")
                readline.redisplay()

            # If we are not blocked at the prompt, better not write now!
            # We would be messing up the output of some command.
            # We'll queue the notification instead to be shown later.
            else:
                self.notifications.append(text)

            # Remember we've seen this bot so we don't notify again.
            self.known_bots.add(bot.uuid)

    # Hook the precmd event to know when we're out of the command prompt. 
Example #21
Source File: shell.py    From koadic with Apache License 2.0 5 votes vote down vote up
def autocomplete(self, text, state):
        import readline
        line = readline.get_line_buffer()
        splitted = line.lstrip().split(" ")

        # if there is a space, delegate to the commands autocompleter
        if len(splitted) > 1:
            if splitted[0] in self.actions:
                if splitted[0] == "set" and splitted[1] == "MODULE" and len(splitted) < 4:
                    return self.actions["use"].autocomplete(self, line, text, state)
                return self.actions[splitted[0]].autocomplete(self, line, text, state)
            else:
                return None

        remap = {
            "?": "help",
            "exploit": "run",
            "execute": "run",
            "options": "info",
            "quit": "exit",
            "sessions": "zombies",
        }

        # no space, autocomplete will be the basic commands:
        options = [x + " " for x in self.actions if x.startswith(text)]
        options.extend([x + " " for x in remap if x.startswith(text)])
        try:
            return options[state]
        except:
            return None 
Example #22
Source File: terminal.py    From weevely3 with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            origline = readline.get_line_buffer()

            # Offer completion just for commands that starts
            # with the trigger :
            if origline and not origline.startswith(':'):
                return None

            line = origline.lstrip().lstrip(':')

            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            if self.completion_matches[state].startswith('alias_'):
                if self.session.get('default_shell') == 'shell_php':
                    return self.completion_matches[state][6:]
                else:
                    return ''
            else:
                return self.completion_matches[state]
        except IndexError:
            return None 
Example #23
Source File: cli.py    From opensips-cli with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """
        auto-complete selection based on given text and state parameters
        """
        if state == 0:
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                mod, args, foo = self.parseline(line)
                if mod == '':
                    return self.complete_modules(text)[state]
                elif not mod in self.modules:
                    logger.error("BUG: mod '{}' not found!".format(mod))
                else:
                    module = self.modules[mod]
                    self.completion_matches = \
                        self.complete_functions(module, text, line, begidx, endidx)
            else:
                self.completion_matches = self.complete_modules(text)
        try:
            return self.completion_matches[state]
        except IndexError:
            return ['']

    # Execute commands from Modules 
Example #24
Source File: completion.py    From polysh with GNU General Public License v2.0 5 votes vote down vote up
def complete(text: str, state: int) -> Optional[str]:
    """On tab press, return the next possible completion"""
    global completion_results
    if state == 0:
        line = readline.get_line_buffer()
        if line.startswith(':'):
            # Control command completion
            completion_results = complete_control_command(line, text)
        else:
            if line.startswith('!') and text and line.startswith(text):
                dropped_exclam = True
                text = text[1:]
            else:
                dropped_exclam = False
            completion_results = []
            # Complete local paths
            completion_results += complete_local_path(text)
            # Complete from history
            l = len(text)
            completion_results += [w + ' ' for w in history_words if
                                   len(w) > l and w.startswith(text)]
            if readline.get_begidx() == 0:
                # Completing first word from $PATH
                completion_results += [w + ' ' for w in user_commands_in_path
                                           if len(w) > l and w.startswith(text)]
            completion_results = remove_dupes(completion_results)
            if dropped_exclam:
                completion_results = ['!' + r for r in completion_results]

    if state < len(completion_results):
        return completion_results[state]
    completion_results = None
    return None 
Example #25
Source File: shell.py    From kitty with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text: str, state: int) -> Optional[str]:
        if state == 0:
            line = readline.get_line_buffer()
            cmdline = shlex.split(line)
            if len(cmdline) < 2 and not line.endswith(' '):
                self.matches = list(cmd_names_matching(text))
            else:
                self.matches = list(options_matching(text, cmdline[0], cmdline[-1], *options_for_cmd(cmdline[0])))
        if state < len(self.matches):
            return self.matches[state]
        return None 
Example #26
Source File: shell.py    From koadic with Apache License 2.0 5 votes vote down vote up
def print_plain(self, text, redraw = False):
        sys.stdout.write("\033[1K\r" + text + os.linesep)
        if self.spool:
            self.spool_log("\033[1K\r", text)

        sys.stdout.flush()

        if redraw or threading.current_thread().ident != self.main_thread_id:
            import readline
            #sys.stdout.write("\033[s")
            sys.stdout.write(self.clean_prompt + readline.get_line_buffer())
            #sys.stdout.write("\033[u\033[B")
            sys.stdout.flush() 
Example #27
Source File: cmd.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #28
Source File: brutespray.py    From brutespray with MIT License 5 votes vote down vote up
def pathCompleter(self,text,state):
        line   = readline.get_line_buffer().split()

        return [x for x in glob.glob(text+'*')][state] 
Example #29
Source File: SharPyShellPrompt.py    From SharPyShell with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            old_delims = readline.get_completer_delims()
            readline.set_completer_delims(old_delims.replace('#', ''))
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
Example #30
Source File: ftp-cmd.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def completer(text, state):
    global _last_line
    global _last_res
    global rl_completion_suppress_append
    if rl_completion_suppress_append is not None:
        rl_completion_suppress_append.value = 1
    try:
        line = readline.get_line_buffer()[:readline.get_endidx()]
        if _last_line != line:
            _last_res = _completer_get_subs(line)
            _last_line = line
        (dir, name, qtype, lastword, subs) = _last_res
        if state < len(subs):
            sn = subs[state]
            sn1 = sn.try_resolve()  # find the type of any symlink target
            fullname = os.path.join(dir, sn.name)
            if stat.S_ISDIR(sn1.mode):
                ret = shquote.what_to_add(qtype, lastword, fullname+'/',
                                          terminate=False)
            else:
                ret = shquote.what_to_add(qtype, lastword, fullname,
                                          terminate=True) + ' '
            return text + ret
    except Exception, e:
        log('\n')
        try:
            import traceback
            traceback.print_tb(sys.exc_traceback)
        except Exception, e2:
            log('Error printing traceback: %s\n' % e2)