From 1edb74ba91912ea9acefe091f854eaa8de8ce14e Mon Sep 17 00:00:00 2001 From: Arav Singhal Date: Thu, 27 Oct 2016 13:01:02 +0530 Subject: [PATCH 1/2] 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. --- functions/utilities.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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" } From 8d7a4e462ae93169be59c07a06c269fc254aa96b Mon Sep 17 00:00:00 2001 From: Arav Singhal Date: Thu, 27 Oct 2016 13:23:22 +0530 Subject: [PATCH 2/2] Update test for required behavior --- test/segments/dir.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 035addea..840a298b 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -60,7 +60,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tm…/po…/1/12/12…/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test