diff options
author | Arav Singhal <singhal.arav@gmail.com> | 2016-10-27 10:31:02 +0300 |
---|---|---|
committer | Arav Singhal <singhal.arav@gmail.com> | 2016-10-27 10:31:02 +0300 |
commit | 1edb74ba91912ea9acefe091f854eaa8de8ce14e (patch) | |
tree | 677845b352d810d035ae4602be2b825fcf38102c | |
parent | c4fdc8f70804fea6f543e6bbf3964301e2537e36 (diff) |
Consider delimiter length in dir truncate right
Truncating the path from the right now takes in account the delimiter
length, so that directories with names shorter than truncated name +
delimiter are displayed properly.
For example, if SHORTEN_DIR_LENGTH is 4 and the delimiter is "..",
"../tests/.." and "../custom/.." are not incorrectly "truncated" to
"../test../.." and "../cust../..", both of which are longer or the same
length as the original.
-rw-r--r-- | functions/utilities.zsh | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/functions/utilities.zsh b/functions/utilities.zsh index c9bd2e46..f27c7f99 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -204,5 +204,7 @@ function segmentShouldBeJoined() { # Given a directory path, truncate it according to the settings for # `truncate_from_right` function truncatePathFromRight() { - echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\//g" + local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER} + echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ + "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" } |