def shorten_path(path: pathlib.Path) -> pathlib.Path:
    """Try to shorten path using special characters like ~.

    Returns original path unmodified if it can't be shortened.
    """
    tilde_home = pathlib.Path('~')
    expanduser_len = len(tilde_home.expanduser().parts)
    if path.parts[:expanduser_len] == tilde_home.expanduser().parts:
        return tilde_home.joinpath(*path.parts[expanduser_len:])
    return path
Try to shorten path using special characters like ~.

    Returns original path unmodified if it can't be shortened.
    
gcalcli/utils.py