def set_path_autocomplete() -> None:
"""Enable file path autocompletion for GNU readline."""
def autocomplete(text: str, state: int) -> str:
expanded_path = os.path.expanduser(text)
if os.path.isdir(expanded_path):
possible_paths = glob.glob(os.path.join(expanded_path, "*"))
else:
possible_paths = glob.glob(expanded_path + "*")
if expanded_path != text:
possible_paths = [contract_user(path) for path in possible_paths]
possible_paths.append(None)
return possible_paths[state]
readline.parse_and_bind("tab: complete")
readline.set_completer_delims("")
readline.set_completer(autocomplete)
评论列表
文章目录