Add ellipsis argument to cwd segment
This commit is contained in:
parent
c3b4654bfb
commit
3f1e621f1d
|
@ -75,17 +75,22 @@ def branch(pl, segment_info, status_colors=False):
|
|||
|
||||
|
||||
@requires_segment_info
|
||||
def cwd(pl, segment_info, dir_shorten_len=None, dir_limit_depth=None, use_path_separator=False):
|
||||
def cwd(pl, segment_info, dir_shorten_len=None, dir_limit_depth=None, use_path_separator=False, ellipsis='⋯'):
|
||||
'''Return the current working directory.
|
||||
|
||||
Returns a segment list to create a breadcrumb-like effect.
|
||||
|
||||
:param int dir_shorten_len:
|
||||
shorten parent directory names to this length (e.g. :file:`/long/path/to/powerline` → :file:`/l/p/t/powerline`)
|
||||
shorten parent directory names to this length (e.g.
|
||||
:file:`/long/path/to/powerline` → :file:`/l/p/t/powerline`)
|
||||
:param int dir_limit_depth:
|
||||
limit directory depth to this number (e.g. :file:`/long/path/to/powerline` → :file:`⋯/to/powerline`)
|
||||
limit directory depth to this number (e.g.
|
||||
:file:`/long/path/to/powerline` → :file:`⋯/to/powerline`)
|
||||
:param bool use_path_separator:
|
||||
Use path separator in place of soft divider.
|
||||
:param str ellipsis:
|
||||
Specifies what to use in place of omitted directories. Use None to not
|
||||
show this subsegment at all.
|
||||
|
||||
Divider highlight group used: ``cwd:divider``.
|
||||
|
||||
|
@ -110,7 +115,8 @@ def cwd(pl, segment_info, dir_shorten_len=None, dir_limit_depth=None, use_path_s
|
|||
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]]
|
||||
if dir_limit_depth and cwd_split_len > dir_limit_depth + 1:
|
||||
del(cwd[0:-dir_limit_depth])
|
||||
cwd.insert(0, '⋯')
|
||||
if ellipsis is not None:
|
||||
cwd.insert(0, ellipsis)
|
||||
ret = []
|
||||
if not cwd[0]:
|
||||
cwd[0] = '/'
|
||||
|
|
|
@ -257,10 +257,24 @@ class TestCommon(TestCase):
|
|||
{'contents': '⋯', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, ellipsis='...'), [
|
||||
{'contents': '...', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, ellipsis=None), [
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True), [
|
||||
{'contents': '⋯/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True, ellipsis='...'), [
|
||||
{'contents': '.../', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True, ellipsis=None), [
|
||||
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
|
||||
])
|
||||
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2), [
|
||||
{'contents': '~', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
|
||||
{'contents': 'fo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
|
||||
|
|
Loading…
Reference in New Issue