From 69e55a30b3a7b5a3f23c8567820c840d59b32244 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 07:40:09 +0400 Subject: Updated tests for resetting bold Updated tests to include the `%b%K{blue}%F{black}` or similar. TODO: Still have to create a test for a bolded last segment --- test/segments/dir.spec | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index ef27e160..31925053 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -26,7 +26,7 @@ function testTruncateFoldersWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}…/12345678/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -44,7 +44,7 @@ function testTruncateMiddleWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -62,7 +62,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/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%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -81,7 +81,7 @@ function testTruncationFromRightWithEmptyDelimiter() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/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%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -102,7 +102,7 @@ function testTruncateWithFolderMarkerWorks() { # Setup folder marker touch $BASEFOLDER/1/12/.shorten_folder_marker cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -123,7 +123,7 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { # Setup folder marker touch $BASEFOLDER/1/12/.xxx cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -156,7 +156,7 @@ function testTruncateWithPackageNameWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -195,7 +195,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -230,7 +230,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -256,7 +256,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -270,7 +270,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -284,7 +284,7 @@ function testChangingDirPathSeparator() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - unset FOLDER @@ -299,20 +299,20 @@ function testHomeFolderAbbreviation() { cd ~/ # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}~%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}qQq%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd /tmp # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd "$dir" } @@ -322,7 +322,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -336,7 +336,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -360,7 +360,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -378,7 +378,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -396,7 +396,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -417,7 +417,7 @@ function testTruncateToUniqueWorks() { mkdir -p /tmp/powerlevel9k-test/bob/docs cd /tmp/powerlevel9k-test/alice/devl - assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}txXxpxXxalxXxde%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test -- cgit v1.2.3 From b6f20d1032496d296a5aed4e059f7001195fb3d5 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:18:35 +0400 Subject: Updating Travis tests for bold dir --- test/powerlevel9k.spec | 14 +++++------ test/segments/dir.spec | 64 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 30 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index e3d571a0..5d8c5a31 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -20,7 +20,7 @@ function testJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %K{blue}%F{black}%F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b %K{blue}%F{black}%F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -30,7 +30,7 @@ function testTransitiveJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %K{blue}%F{black}%F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b %K{blue}%F{black}%F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -40,7 +40,7 @@ function testJoiningWithConditionalSegment() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %K{blue}%F{black} %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b %K{blue}%F{black} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -51,7 +51,7 @@ function testDynamicColoringOfSegmentsWork() { POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' cd /tmp - assertEquals "%K{red} %F{black}/tmp%b%K{red}%F{black} %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{black}/tmp%b %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{blue} %F{green%}icon-here%f %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{green%}icon-here%f %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -86,7 +86,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{yellow} %F{green%}icon-here%f %F{red}/tmp%b%K{blue}%F{black} %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{green%}icon-here%f %F{red}/tmp%b %k%F{yellow}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -106,7 +106,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{blue} %F{black%}icon-here%f %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}icon-here%f %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 31925053..d1a496e7 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -26,7 +26,7 @@ function testTruncateFoldersWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}…/12345678/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}…/12345678/123456789%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -44,7 +44,7 @@ function testTruncateMiddleWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -62,7 +62,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789%b% %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -81,7 +81,7 @@ function testTruncationFromRightWithEmptyDelimiter() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -102,7 +102,7 @@ function testTruncateWithFolderMarkerWorks() { # Setup folder marker touch $BASEFOLDER/1/12/.shorten_folder_marker cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -123,7 +123,7 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { # Setup folder marker touch $BASEFOLDER/1/12/.xxx cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -156,7 +156,7 @@ function testTruncateWithPackageNameWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789%b %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -195,7 +195,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer%b %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -230,7 +230,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads%b %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -244,7 +244,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{blue} %F{black%}home-icon%f %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}home-icon%f %F{black}~%b %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -256,7 +256,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -270,7 +270,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -284,7 +284,7 @@ function testChangingDirPathSeparator() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" cd - unset FOLDER @@ -299,20 +299,20 @@ function testHomeFolderAbbreviation() { cd ~/ # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}~%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}~%b %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}qQq%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}qQq%b %k%F{blue}%f " "$(build_left_prompt)" cd /tmp # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}/tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" cd "$dir" } @@ -322,7 +322,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp%b %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -336,7 +336,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -360,7 +360,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}xXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -378,7 +378,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -396,7 +396,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -417,7 +417,7 @@ function testTruncateToUniqueWorks() { mkdir -p /tmp/powerlevel9k-test/bob/docs cd /tmp/powerlevel9k-test/alice/devl - assertEquals "%K{blue} %F{black}txXxpxXxalxXxde%b%K{blue}%F{black} %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}txXxpxXxalxXxde%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -427,4 +427,22 @@ function testTruncateToUniqueWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testBoldHomeDirectoryWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD +} + +function testBoldOtherDirectoryWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + cd /tmp + + assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD +} + source shunit2/source/2.1/src/shunit2 -- cgit v1.2.3 From 1e54872873270b89700c3f88783bdc301ba40e50 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:30:21 +0400 Subject: Added test for Home folder highlighting --- test/segments/dir.spec | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index d1a496e7..41f82eca 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -429,9 +429,11 @@ function testTruncateToUniqueWorks() { function testBoldHomeDirectoryWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + cd ~ assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" + cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } @@ -445,4 +447,14 @@ function testBoldOtherDirectoryWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } +function testDirHighlightHomeWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + cd ~ + + assertEquals "%K{blue} %F{black}%F{red}~%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND +} + source shunit2/source/2.1/src/shunit2 -- cgit v1.2.3 From dba80dbee922fee79b8709ac7fa981867bed89c5 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:48:25 +0400 Subject: Added tests for other folder highlighing --- test/segments/dir.spec | 82 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 41f82eca..221ccea2 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -62,7 +62,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789%b% %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789%b %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -437,7 +437,29 @@ function testBoldHomeDirectoryWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } -function testBoldOtherDirectoryWorks() { +function testBoldHomeSubdirWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{blue} %F{black}~/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD +} + +function testBoldRootDirectoryWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + cd / + + assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD +} + +function testBoldRootSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd /tmp @@ -447,7 +469,17 @@ function testBoldOtherDirectoryWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } -function testDirHighlightHomeWorks() { +function testBoldRootSubsubdirWorks() { + mkdir -p /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{blue} %F{black}/tmp/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testHighlightHomeWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd ~ @@ -457,4 +489,48 @@ function testDirHighlightHomeWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } +function testHighlightHomeSubdirWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{blue} %F{black}~/%F{red}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND +} + +function testHighlightRootWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + cd / + + assertEquals "%K{blue} %F{black}%F{red}/%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND +} + +function testHighlightRootSubdirDirectoryWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + cd /tmp + + assertEquals "%K{blue} %F{black}/%F{red}tmp%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND +} + +function testHighlightRootSubdirDirectoryWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + mkdir /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{blue} %F{black}/tmp/%F{red}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND +} + source shunit2/source/2.1/src/shunit2 -- cgit v1.2.3 From 276bc9017c99591cfdab373f659182c7e9166063 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 14:05:49 +0400 Subject: Updated testBoldRootSubsubdirWorks() Forgot to initialize the bolding variable --- test/segments/dir.spec | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 221ccea2..a7be9fe2 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -470,6 +470,7 @@ function testBoldRootSubdirWorks() { } function testBoldRootSubsubdirWorks() { + POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -477,6 +478,7 @@ function testBoldRootSubsubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testHighlightHomeWorks() { -- cgit v1.2.3 From 4fc4d157037bcef7d3c3610463dbbdb8b919a2c9 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 14:17:50 +0400 Subject: Added tests for DIR_PATH_SEPARATOR_FOREGROUND --- test/segments/dir.spec | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index a7be9fe2..7d158389 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -427,7 +427,7 @@ function testTruncateToUniqueWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } -function testBoldHomeDirectoryWorks() { +function testBoldHomeDirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd ~ @@ -449,7 +449,7 @@ function testBoldHomeSubdirWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } -function testBoldRootDirectoryWorks() { +function testBoldRootDirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd / @@ -469,7 +469,7 @@ function testBoldRootSubdirWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } -function testBoldRootSubsubdirWorks() { +function testBoldRootSubSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -513,7 +513,7 @@ function testHighlightRootWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } -function testHighlightRootSubdirDirectoryWorks() { +function testHighlightRootSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd /tmp @@ -523,7 +523,7 @@ function testHighlightRootSubdirDirectoryWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } -function testHighlightRootSubdirDirectoryWorks() { +function testHighlightRootSubSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -535,4 +535,28 @@ function testHighlightRootSubdirDirectoryWorks() { unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } +function testDirSeparatorColorHomeSubdirWorks() { + POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{blue} %F{black}~%F{red}/%F{black}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND +} + +function testDirSeparatorColorRootSubSubdirWorks() { + POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + mkdir -p /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{blue} %F{black}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND +} + source shunit2/source/2.1/src/shunit2 -- cgit v1.2.3 From 441fb277d92a6e2310a71caa3920be1276a39afe Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 23:34:25 +0400 Subject: Comments, trunc_to_last, trunc_absolute Added comments throughout the code Added `truncate_to_last` - displays only the current folder Added `truncate_absolute` - displays only the last POWERLEVEL9K_SHORTER_DIR_LENGTH characters - see #736 --- powerlevel9k.zsh-theme | 52 ++++++++++++++++++++------- test/segments/dir.spec | 96 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 106 insertions(+), 42 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e65a82e0..ebf13e66 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -724,21 +724,39 @@ set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" + # save this path so that we can use the pure path for STATE icons and colors later. + local state_path=$current_path + # declare all local variables local paths directory test_dir test_dir_length trunc_path threshhold - (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() # only split if not root/home folder - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then + # if we are not in "~" or "/", split the paths into an array + (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() + # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" - local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character + # convert delimiter from unicode to literal character, so that we can get the correct length later + local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) + # truncate characters from the middle of the path current_path=$(truncatePath $current_path $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER "middle") ;; truncate_from_right) + # truncate characters from the right of the path current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) ;; + truncate_to_last) + # truncate all characters before the current directory + current_path=${current_path##*/} + ;; + truncate_absolute) + # truncate all characters except the last POWERLEVEL9K_SHORTEN_DIR_LENGTH characters + if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-$POWERLEVEL9K_SHORTEN_DIR_LENGTH)} + fi + ;; truncate_with_folder_marker) - if (( ${#paths} > 0 )); then # root is an exception and won't have paths + if (( ${#paths} > 0 )); then # root and home are exceptions and won't have paths, so skip this local last_marked_folder marked_folder set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" @@ -844,7 +862,8 @@ prompt_dir() { esac fi - local path_opt=$current_path # save state of path for highlighting and bold options + # save state of path for highlighting and bold options + local path_opt=$current_path if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then current_path="${current_path[2,-1]}" @@ -860,14 +879,15 @@ prompt_dir() { local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ $current_path == '~' ]]; then + elif [[ $state_path == '~' ]]; then current_state="HOME" - elif [[ $current_path == '~'* ]]; then + elif [[ $state_path == '~'* ]]; then current_state="HOME_SUBFOLDER" fi + # declare variables used for bold and state colors local bld dir_state_foreground dir_state_user_foreground - [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]] && bld="%B" || bld="" + [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]] && bld_on="%B"; bld_off="%b" || bld_on=""; bld_off="" local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND local dir_state_foreground=${(P)dir_state_user_foreground} @@ -879,15 +899,23 @@ prompt_dir() { if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}%b" + current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}${bld_off}" else - current_path="${dir_name}/${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b" + if [[ $dir_name != $base_name ]]; then + current_path="${dir_name}/${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" + else + current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" + fi fi else if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="${bld}${current_path}%b" + current_path="${bld_on}${current_path}${bld_off}" else - current_path="${dir_name}/${bld}${base_name}%b" + if [[ $dir_name != $base_name ]]; then + current_path="${dir_name}/${bld_on}${base_name}${bld_off}" + else + current_path="${bld_on}${base_name}${bld_off}" + fi fi fi diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 7d158389..e313c01c 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -26,7 +26,7 @@ function testTruncateFoldersWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}…/12345678/123456789%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -44,7 +44,7 @@ function testTruncateMiddleWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -62,7 +62,43 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789%b %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 + + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + +function testTruncateToLastWorks() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + + FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{blue} %F{black}123456789 %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + +function testTruncateAbsoluteWorks() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + + FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{blue} %F{black}…89 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -81,7 +117,7 @@ function testTruncationFromRightWithEmptyDelimiter() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789%b %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 @@ -102,7 +138,7 @@ function testTruncateWithFolderMarkerWorks() { # Setup folder marker touch $BASEFOLDER/1/12/.shorten_folder_marker cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -123,7 +159,7 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { # Setup folder marker touch $BASEFOLDER/1/12/.xxx cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -156,7 +192,7 @@ function testTruncateWithPackageNameWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -195,7 +231,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -230,7 +266,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -244,7 +280,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{blue} %F{black%}home-icon%f %F{black}~%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}home-icon%f %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -256,7 +292,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}sub-icon%f %F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -270,7 +306,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -284,7 +320,7 @@ function testChangingDirPathSeparator() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - unset FOLDER @@ -299,20 +335,20 @@ function testHomeFolderAbbreviation() { cd ~/ # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}~%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}qQq%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)" cd /tmp # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" cd "$dir" } @@ -322,7 +358,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -336,7 +372,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon%f %F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -360,7 +396,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}xXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -378,7 +414,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -396,7 +432,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -417,7 +453,7 @@ function testTruncateToUniqueWorks() { mkdir -p /tmp/powerlevel9k-test/bob/docs cd /tmp/powerlevel9k-test/alice/devl - assertEquals "%K{blue} %F{black}txXxpxXxalxXxde%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -485,7 +521,7 @@ function testHighlightHomeWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd ~ - assertEquals "%K{blue} %F{black}%F{red}~%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -496,7 +532,7 @@ function testHighlightHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{blue} %F{black}~/%F{red}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}~/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -507,7 +543,7 @@ function testHighlightRootWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd / - assertEquals "%K{blue} %F{black}%F{red}/%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -517,7 +553,7 @@ function testHighlightRootSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd /tmp - assertEquals "%K{blue} %F{black}/%F{red}tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -528,7 +564,7 @@ function testHighlightRootSubSubdirWorks() { mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{blue} %F{black}/tmp/%F{red}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -540,7 +576,7 @@ function testDirSeparatorColorHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{blue} %F{black}~%F{red}/%F{black}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}~%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -552,7 +588,7 @@ function testDirSeparatorColorRootSubSubdirWorks() { mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{blue} %F{black}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test -- cgit v1.2.3 From 1abb519f593e42e92ebc7714723bced6d746f934 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 00:45:00 +0400 Subject: Updated dir.spec tests --- test/segments/dir.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index e313c01c..8c9554d7 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -92,7 +92,7 @@ function testTruncateToLastWorks() { function testTruncateAbsoluteWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER -- cgit v1.2.3 From 08432bf70c1874ab4f67538f85e7be50847f1c5d Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:28:56 +0400 Subject: Added truncate_to_first_and_last strategy Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. --- README.md | 3 ++- powerlevel9k.zsh-theme | 71 ++++++++++++++++++++++++++++++-------------------- test/segments/dir.spec | 18 +++++++++++++ 3 files changed, 63 insertions(+), 29 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/README.md b/README.md index 6642b93f..1dbe756e 100644 --- a/README.md +++ b/README.md @@ -377,8 +377,9 @@ Customizations available are: |Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`| |`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).| |`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| -|`truncate_to_last`|Truncates everything before the last folder in the path.| |`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3`, you will get "..l9k".| +|`truncate_to_last`|Truncates everything before the last folder in the path.| +|`truncate_to_first_and_last|Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get "~/../powerlevel9k".|| |`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.| |`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| |`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).| diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 10e9852d..17909c61 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -728,7 +728,7 @@ prompt_dir() { local state_path=$current_path # declare all local variables local paths directory test_dir test_dir_length trunc_path threshhold - # if we are not in "~" or "/", split the paths into an array + # if we are not in "~" or "/", split the paths into an array and exclude "~" (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then @@ -745,16 +745,54 @@ prompt_dir() { # truncate characters from the right of the path current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) ;; - truncate_to_last) - # truncate all characters before the current directory - current_path=${current_path##*/} - ;; truncate_absolute) # truncate all characters except the last POWERLEVEL9K_SHORTEN_DIR_LENGTH characters if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} fi ;; + truncate_to_last) + # truncate all characters before the current directory + current_path=${current_path##*/} + ;; + truncate_to_first_and_last) + if (( ${#current_path} > 1 )) && (( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} > 0 )); then + threshhold=$(( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} * 2)) + # if we are in "~", add it back into the paths array + [[ $current_path == '~'* ]] && paths=("~" "${paths[@]}") + if (( ${#paths} > $threshhold )); then + local num=$(( ${#paths} - ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} )) + # repace the middle elements + for (( i=$POWERLEVEL9K_SHORTEN_DIR_LENGTH; i<$num; i++ )); do + paths[$i+1]=$POWERLEVEL9K_SHORTEN_DELIMITER + done + current_path="${(j:/:)paths}" + fi + fi + ;; + truncate_to_unique) + # for each parent path component find the shortest unique beginning + # characters sequence. Source: https://stackoverflow.com/a/45336078 + if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths + local matching + local cur_path='/' + [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' + for directory in ${paths[@]}; do + test_dir='' + for (( i=0; i<${#directory}; i++ )); do + test_dir+="${directory:$i:1}" + matching=("$cur_path"/"$test_dir"*/) + if [[ ${#matching[@]} -eq 1 ]]; then + break + fi + done + trunc_path+="$test_dir/" + cur_path+="$directory/" + done + [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path" + current_path="${trunc_path: : -1}" + fi + ;; truncate_with_folder_marker) if (( ${#paths} > 0 )); then # root and home are exceptions and won't have paths, so skip this local last_marked_folder marked_folder @@ -833,29 +871,6 @@ prompt_dir() { current_path="`echo $packageName | tr -d '"'`$subdirectory_path" fi ;; - truncate_to_unique) - # for each parent path component find the shortest unique beginning - # characters sequence. Source: https://stackoverflow.com/a/45336078 - if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths - local matching - local cur_path='/' - [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' - for directory in ${paths[@]}; do - test_dir='' - for (( i=0; i<${#directory}; i++ )); do - test_dir+="${directory:$i:1}" - matching=("$cur_path"/"$test_dir"*/) - if [[ ${#matching[@]} -eq 1 ]]; then - break - fi - done - trunc_path+="$test_dir/" - cur_path+="$directory/" - done - [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path" - current_path="${trunc_path: : -1}" - fi - ;; *) current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" ;; diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 8c9554d7..3e7f11d4 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -90,6 +90,24 @@ function testTruncateToLastWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncateToFirstAndLastWorks() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" + + FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{blue} %F{black}/tmp/12/…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + function testTruncateAbsoluteWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" -- cgit v1.2.3 From 3674af1cd9788b144a39358913f95979762dbb00 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:37:49 +0400 Subject: Updated dir.spec test for first_and_last --- test/segments/dir.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 3e7f11d4..12242961 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -98,7 +98,7 @@ function testTruncateToFirstAndLastWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/12/…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test -- cgit v1.2.3 From ddcdad77a73d971a77283d90fd3ba78e0f61dc66 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:08:43 +0400 Subject: Added new variable POWERLEVEL9K_DIR_PATH_ABSOLUTE If user sets POWERLEVEL9K_DIR_PATH_ABSOLUTE to true, uses absolute paths instead of home folder abbreviation, e.g. /Users/chris/... instead of ~/... --- powerlevel9k.zsh-theme | 9 ++++++--- test/segments/dir.spec | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d60219eb..c404c0c2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -723,7 +723,10 @@ set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { - local current_path="$(print -P '%~')" + # using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE + local current_path=$PWD # WAS: local current_path="$(print -P '%~')" + # check if the user wants to use absolute paths or "~" paths + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"} # save this path so that we can use the pure path for STATE icons and colors later. local state_path=$current_path # declare all local variables @@ -891,9 +894,9 @@ prompt_dir() { local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ $state_path == '~' ]]; then + elif [[ $state_path == $HOME ]]; then # changed '~' to $HOME for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE current_state="HOME" - elif [[ $state_path == '~'* ]]; then + elif [[ $state_path == $HOME* ]]; then # changed '~'* to $HOME* for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE current_state="HOME_SUBFOLDER" fi diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 12242961..efe99672 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -18,6 +18,16 @@ function tearDown() { unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } +function testAbsolutePathWorks() { + POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + + cd ~ + assertEquals "%K{blue} %F{black}…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + + cd - + unset POWERLEVEL9K_DIR_PATH_ABSOLUTE +} + function testTruncateFoldersWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' -- cgit v1.2.3 From 75a763f9018595ad861966e11de560ab00b8cd87 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:12:56 +0400 Subject: Updated test for POWERLEVEL9K_DIR_PATH_ABSOLUTE --- test/segments/dir.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/segments/dir.spec') diff --git a/test/segments/dir.spec b/test/segments/dir.spec index efe99672..66009a86 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -18,11 +18,11 @@ function tearDown() { unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } -function testAbsolutePathWorks() { +function testDirPathAbsoluteWorks() { POWERLEVEL9K_DIR_PATH_ABSOLUTE=true cd ~ - assertEquals "%K{blue} %F{black}…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/home/travis %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_ABSOLUTE -- cgit v1.2.3