'Completer function that Cmd will register with readline using
readline.set_completer().  This function will be called by readline
as complete(text, state) where text is a fragment to complete and
state is an integer (0..n).  Each call returns a string with a new
completion.  When no more are available, None is returned.'

def complete(self, text, state, line=None):

    if (line is None):
        import readline
        line = readline.get_line_buffer()
    phrase = line.split(';')[(-1)]
    matches = []
    if (not phrase.strip()):
        matches = self._complete_actions(text)
    else:
        words = phrase.split()
        action = words[0]
        if ((len(words) == 1) and (not phrase.endswith('    '))):
            matches = self._complete_actions(text)
        elif (action in 'help'):
            matches = self._complete_actions(text)
        elif (action in ('add', 'remove', 'update')):
            matches = self._complete_groups(text)
        elif (action in ('clear', 'fg', 'pid', 'restart', 'signal', 'start', 'status', 'stop', 'tail')):
            matches = self._complete_processes(text)
    if (len(matches) > state):
        return matches[state]
