utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:zielen 作者: lostatc 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号