code: def complete(text, state):
      
      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
docs: On tab press, return the next possible completion