gui.model.complete_path

gui.model.complete_path(text)

Complete a directory path the way a shell does on Tab.

Parameters

Name Type Description Default
text str What the user typed. A leading ~ is kept. required

Returns

Name Type Description
tuple[str, list[str]] tuple[str, list[str]]: The text extended by the longest common prefix of the matching sub-directories (and a slash if exactly one matches), and the names of all matches.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen.gui.model import complete_path

with TemporaryDirectory() as tmp:
    for name in ("alpha", "alpine", "beta"):
        (Path(tmp) / name).mkdir()
    print(complete_path(f"{tmp}/be")[0].replace(tmp, "<tmp>"))
    print(complete_path(f"{tmp}/al")[1])
<tmp>/beta/
['alpha', 'alpine']