r"""
    Shows only a little bit of the path. Up to the n bottom-level directories

    TODO: rename to path_tail? ndir_split?

    Returns:
        (str) the trailing n paths of path.

    CommandLine:
        python3 -m utool.util_path --test-path_ndir_split
        python3 -m utool --tf path_ndir_split
        python -m utool --tf path_ndir_split


    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> paths = [r'/usr/bin/local/foo/bar',
        ...          r'C:/',
        ...          #r'lonerel',
        ...          #r'reldir/other',
        ...          r'/ham',
        ...          r'./eggs',
        ...          r'/spam/eggs',
        ...          r'C:\Program Files (x86)/foobar/bin']
        >>> N = 2
        >>> iter_ = ut.iprod(paths, range(1, N + 1))
        >>> force_unix = True
        >>> tuplist = [(n, path_ndir_split(path_, n)) for path_, n in iter_]
        >>> chunklist = list(ut.ichunks(tuplist, N))
        >>> list_ = [['n=%r: %s' % (x, ut.reprfunc(y)) for x, y in chunk]
        >>>          for chunk in chunklist]
        >>> line_list = [', '.join(strs) for strs in list_]
        >>> result = '\n'.join(line_list)
        >>> print(result)
        n=1: '.../bar', n=2: '.../foo/bar'
        n=1: 'C:/', n=2: 'C:/'
        n=1: '.../ham', n=2: '/ham'
        n=1: '.../eggs', n=2: './eggs'
        n=1: '.../eggs', n=2: '.../spam/eggs'
        n=1: '.../bin', n=2: '.../foobar/bin'

def path_ndir_split(path_, n, force_unix=True, winroot='C:', trailing=True):
    r"""
    Shows only a little bit of the path. Up to the n bottom-level directories

    TODO: rename to path_tail? ndir_split?

    Returns:
        (str) the trailing n paths of path.

    CommandLine:
        python3 -m utool.util_path --test-path_ndir_split
        python3 -m utool --tf path_ndir_split
        python -m utool --tf path_ndir_split


    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> paths = [r'/usr/bin/local/foo/bar',
        ...          r'C:/',
        ...          #r'lonerel',
        ...          #r'reldir/other',
        ...          r'/ham',
        ...          r'./eggs',
        ...          r'/spam/eggs',
        ...          r'C:\Program Files (x86)/foobar/bin']
        >>> N = 2
        >>> iter_ = ut.iprod(paths, range(1, N + 1))
        >>> force_unix = True
        >>> tuplist = [(n, path_ndir_split(path_, n)) for path_, n in iter_]
        >>> chunklist = list(ut.ichunks(tuplist, N))
        >>> list_ = [['n=%r: %s' % (x, ut.reprfunc(y)) for x, y in chunk]
        >>>          for chunk in chunklist]
        >>> line_list = [', '.join(strs) for strs in list_]
        >>> result = '\n'.join(line_list)
        >>> print(result)
        n=1: '.../bar', n=2: '.../foo/bar'
        n=1: 'C:/', n=2: 'C:/'
        n=1: '.../ham', n=2: '/ham'
        n=1: '.../eggs', n=2: './eggs'
        n=1: '.../eggs', n=2: '.../spam/eggs'
        n=1: '.../bin', n=2: '.../foobar/bin'
    """
    if not isinstance(path_, six.string_types):
        # Probably given a file pointer
        return path_

    if n is None:
        cplat_path = ensure_crossplat_path(path_)
    elif n == 0:
        cplat_path = ''
    else:
        sep = '/' if force_unix else os.sep
        ndirs_list = []
        head = path_
        reached_end = False
        for nx in range(n):
            head, tail = split(head)
            if tail == '':
                if head == '':
                    reached_end = True
                else:
                    root = head if len(ndirs_list) == 0 else head.strip('\\/')
                    ndirs_list.append(root)
                    reached_end = True
                break
            else:
                ndirs_list.append(tail)
        if trailing and not reached_end:
            head, tail = split(head)
            if len(tail) == 0:
                if len(head) == 0:  # or head == '/':
                    reached_end = True
        ndirs = sep.join(ndirs_list[::-1])
        cplat_path = ensure_crossplat_path(ndirs)
        #if trailing and not reached_end:
        if trailing and not reached_end:
            cplat_path = '.../' + cplat_path
    return cplat_path