Merge 853d1d56f555b12d7922cd77f19e7808fcb8be9a into 574bb1887b9f27b3c046c6b74a1f3ed75b115a75

This commit is contained in:
Christophe Henry 2024-10-04 09:53:35 +02:00 committed by GitHub
commit 8908a0e91f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -52,7 +52,7 @@ class CwdSegment(Segment):
else:
return super(CwdSegment, self).omitted_args(name, method)
def get_shortened_path(self, pl, segment_info, shorten_home=True, **kwargs):
def get_shortened_path(self, pl, segment_info, shorten_home=True, path_aliases=None, **kwargs):
try:
path = out_u(segment_info['getcwd']())
except OSError as e:
@ -63,7 +63,12 @@ class CwdSegment(Segment):
return '[not found]'
else:
raise
if shorten_home:
if isinstance(path_aliases, dict):
for alias_target, alias in path_aliases.items():
alias_target = os.path.expanduser(out_u(alias_target))
if path.startswith(alias_target):
path = out_u(alias) + path[len(alias_target):]
elif shorten_home:
home = segment_info['home']
if home:
home = out_u(home)
@ -122,6 +127,10 @@ Returns a segment list to create a breadcrumb-like effect.
Use path separator in place of soft divider.
:param bool shorten_home:
Shorten home directory to ``~``.
:param dict path_aliases
Define aliases for well-known paths. Directory starting with one
of theses aliases will be shortenened to the provided alias.
Example: {"~/Music": "🎵"}
:param str ellipsis:
Specifies what to use in place of omitted directories. Use None to not
show this subsegment at all.