def get_custom_path_repr(path):
    """Return a custom string representation of given path.

    Parameters
    ==========
    path (pathlib.Path instance)
        path used to retrieve information for
        the custom title

    The custom format is inspired in vim text editor
    window caption: filename followed by parent folder
    surrounded by parenthesis. The parent folder has
    the 'home' portion collapsed, that is, represented
    by a '~' character.
    """
    ### separate path of level file into name and parent
    name, parent = path.name, path.parent

    ### try turning parent into its version relative to
    ### the user directory
    try:
        relative_path = parent.relative_to(Path.home())

    ### if the a ValueError is raised (happens when
    ### the path is not a subpath of the path given to
    ### Path.relative_to), use the entire stringified
    ### parent as the 'parent' part in the custom format
    except ValueError:
        parent = str(parent)

    ### otherwise use a stringified path which is the
    ### result of joining the '~' path (the user
    ### directory) with the version of the parent
    ### relative to the user directory
    else:
        parent = str(Path("~") / relative_path)

    ## assign information to title text
    return "{} ({})".format(name, parent)
Return a custom string representation of given path.

    Parameters
    ==========
    path (pathlib.Path instance)
        path used to retrieve information for
        the custom title

    The custom format is inspired in vim text editor
    window caption: filename followed by parent folder
    surrounded by parenthesis. The parent folder has
    the 'home' portion collapsed, that is, represented
    by a '~' character.
    
nodezator/ourstdlibs/path.py