MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / shell_cmd_complete

Method shell_cmd_complete

cmd2/cmd2.py:2291–2316  ·  view source on GitHub ↗

Perform completion of executables either in a user's path or a given path. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the

(
        self, text: str, line: str, begidx: int, endidx: int, *, complete_blank: bool = False
    )

Source from the content-addressed store, hash-verified

2289 return Completions(items=items, allow_finalization=allow_finalization)
2290
2291 def shell_cmd_complete(
2292 self, text: str, line: str, begidx: int, endidx: int, *, complete_blank: bool = False
2293 ) -> Completions:
2294 """Perform completion of executables either in a user's path or a given path.
2295
2296 :param text: the string prefix we are attempting to match (all matches must begin with it)
2297 :param line: the current input line with leading whitespace removed
2298 :param begidx: the beginning index of the prefix text
2299 :param endidx: the ending index of the prefix text
2300 :param complete_blank: If True, then a blank will complete all shell commands in a user's path. If False, then
2301 no completion is performed. Defaults to False to match Bash shell behavior.
2302 :return: a Completions object
2303 """
2304 # Don't complete anything if no shell command has been started
2305 if not complete_blank and not text:
2306 return Completions()
2307
2308 # If there are no path characters in the search text, then do shell command completion in the user's path
2309 if not text.startswith("~") and os.path.sep not in text:
2310 items = [CompletionItem(exe) for exe in utils.get_exes_in_path(text)]
2311 return Completions(items=items)
2312
2313 # Otherwise look for executables in the given path
2314 return self.path_complete(
2315 text, line, begidx, endidx, path_filter=lambda path: os.path.isdir(path) or os.access(path, os.X_OK)
2316 )
2317
2318 def _redirect_complete(self, text: str, line: str, begidx: int, endidx: int, compfunc: BoundCompleter) -> Completions:
2319 """First completion function for all commands, called by complete().

Callers 1

_redirect_completeMethod · 0.95

Calls 3

path_completeMethod · 0.95
CompletionsClass · 0.85
CompletionItemClass · 0.85

Tested by

no test coverage detected