def prepend_dir()

in src/pathpicker/parse.py [0:0]


def prepend_dir(file: str, with_file_inspection: bool = False) -> str:
    if not file or len(file) < 2:
        return file

    if file[0] == "/":
        return file

    if file[0:4] == ".../":
        # these are the gross git abbreviated paths, so
        # return early since we cant do anything here
        return file

    if file[0:2] == "~/":
        # need to absolute it
        return os.path.expanduser(file)

    # if it starts with relative dirs (grep), then that's the easiest
    # because abspath will resolve this
    if file[0:2] == "./" or file[0:3] == "../":
        return file

    # some peeps do forcedir and expand the path beforehand,
    # so lets check for that case here
    first = file.split(os.sep)[0]
    if first == "home" and not os.environ.get("FPP_DISABLE_PREPENDING_HOME_WITH_SLASH"):
        # already absolute, easy
        return "/" + file

    if first in REPOS + (os.environ.get("FPP_REPOS") or "").split(","):
        return os.path.expanduser("~/" + file)

    if "/" not in file:
        # assume current dir like ./
        return "./" + file

    # git show and diff has a/stuff and b/stuff, so handle that. git
    # status never does this so we don't need to worry about relative dirs
    if file[0:2] == "a/" or file[0:2] == "b/":
        return PREPEND_PATH + file[2:]

    split_up = file.split("/")
    if split_up[0] == "www":
        return PREPEND_PATH + "/".join(split_up[1:])

    if not with_file_inspection:
        # hope
        return PREPEND_PATH + "/".join(split_up)
    # Alright we need to handle the case where git status returns
    # relative paths where every other git command returns paths relative
    # to the top-level dir. so lets see if PREPEND_PATH is not a file whereas
    # relative is...
    top_level_path = PREPEND_PATH + "/".join(split_up)
    relative_path = "./" + "/".join(split_up)
    if not os.path.isfile(top_level_path) and os.path.isfile(relative_path):
        return relative_path
    return top_level_path