From 085a78b9b823ff1731070b229a9154bd4ade63b9 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 10 Feb 2018 13:54:05 +0400 Subject: [PATCH 01/64] Incorporated @dritter 's changes into next These are the changes made by @dritter on `async_all_the_segments` --- powerlevel9k.zsh-theme | 47 ++++++++---------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c32ccd48..26936325 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -718,21 +718,20 @@ prompt_command_execution_time() { # Dir: current working directory set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" -set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false +# Parameters: +# * $1 Alignment: string - left|right +# * $2 Index: integer prompt_dir() { - local tmp="$IFS" - local IFS="" - local current_path=$(pwd | sed -e "s,^$HOME,~,") - local IFS="$tmp" + local current_path="$(print -P "%~")" if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") ;; truncate_from_right) - current_path=$(truncatePathFromRight "$current_path" ) + current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) ;; truncate_with_package_name) local name repo_path package_path current_dir zero @@ -782,12 +781,8 @@ prompt_dir() { # Instead of printing out the full path, print out the name of the package # from the package.json and append the current subdirectory current_path="`echo $packageName | tr -d '"'`$subdirectory_path" - if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - # add space before the packageName to allow for removing the "first" character, without messing up the package name. - current_path=" ${current_path}" - fi else - current_path=$(truncatePathFromRight "$current_path" ) + current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; truncate_with_folder_marker) @@ -816,27 +811,6 @@ prompt_dir() { # the current path. current_path=$current_path${PWD#${last_marked_folder}*} ;; - truncate_to_unique) - # for each parent path component find the shortest unique beginning - # characters sequence. Source: https://stackoverflow.com/a/45336078 - paths=(${(s:/:)PWD}) - cur_path='/' - cur_short_path='/' - for directory in ${paths[@]} - do - cur_dir='' - for (( i=0; i<${#directory}; i++ )); do - cur_dir+="${directory:$i:1}" - matching=("$cur_path"/"$cur_dir"*/) - if [[ ${#matching[@]} -eq 1 ]]; then - break - fi - done - cur_short_path+="$cur_dir/" - cur_path+="$directory/" - done - current_path="${cur_short_path: : -1}" - ;; *) current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" ;; @@ -852,7 +826,7 @@ prompt_dir() { fi if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then - current_path=${current_path/#\~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}} + current_path="$( echo "${current_path}" | sed "s/^~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/")" fi typeset -AH dir_states @@ -860,12 +834,9 @@ prompt_dir() { "DEFAULT" "FOLDER_ICON" "HOME" "HOME_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON" - "NOT_WRITABLE" "LOCK_ICON" ) local current_state="DEFAULT" - if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then - current_state="NOT_WRITABLE" - elif [[ $(print -P "%~") == '~' ]]; then + if [[ $(print -P "%~") == '~' ]]; then current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER" From 6d25e18779f33cd3339ecd491b3a195a714519ae Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 10 Feb 2018 14:23:27 +0400 Subject: [PATCH 02/64] Merged `truncate_to_unique` & state `NOT_WRITABLE` Added `truncate_to_unique` and `NOT_WRITABLE` to @dritter's code. --- powerlevel9k.zsh-theme | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 26936325..87b453a4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -811,6 +811,27 @@ prompt_dir() { # the current path. current_path=$current_path${PWD#${last_marked_folder}*} ;; + truncate_to_unique) + # for each parent path component find the shortest unique beginning + # characters sequence. Source: https://stackoverflow.com/a/45336078 + paths=(${(s:/:)PWD}) + cur_path='/' + cur_short_path='/' + for directory in ${paths[@]} + do + cur_dir='' + for (( i=0; i<${#directory}; i++ )); do + cur_dir+="${directory:$i:1}" + matching=("$cur_path"/"$cur_dir"*/) + if [[ ${#matching[@]} -eq 1 ]]; then + break + fi + done + cur_short_path+="$cur_dir/" + cur_path+="$directory/" + done + current_path="${cur_short_path: : -1}" + ;; *) current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" ;; @@ -834,9 +855,12 @@ prompt_dir() { "DEFAULT" "FOLDER_ICON" "HOME" "HOME_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON" + "NOT_WRITABLE" "LOCK_ICON" ) local current_state="DEFAULT" - if [[ $(print -P "%~") == '~' ]]; then + if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then + current_state="NOT_WRITABLE" + elif [[ $(print -P "%~") == '~' ]]; then current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER" From ccba1cc8233143f7e360a3ab3ff61b7175327acf Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 10 Feb 2018 14:46:56 +0400 Subject: [PATCH 03/64] PROMPT_DIR color/bold on last dir & color for sep. You can now set the last dir to have a custom color with `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND` and whether it will be bold with `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true`. You can also set a custom separator color with `POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND`. --- README.md | 4 ++++ powerlevel9k.zsh-theme | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 74edc446..7f9ee9ca 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,10 @@ You can also configure the `dir` segment to show when you are in a directory wit |----------|---------------|-------------| |`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)). Note that this functionality is also available in a separate segment, `dir_writable`.| +If you want to customize the last directory of the path, you can now set `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND` to a custom color and/or `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true` to display that part in bold. + +You can also color the separator separately by setting the color using `POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND`. + ##### disk_usage The `disk_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 87b453a4..faaa32ec 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -838,18 +838,12 @@ prompt_dir() { esac fi + local path_opt=$current_path # save state of path for highlighting and bold options + if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then current_path="${current_path[2,-1]}" fi - if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then - current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" - fi - - if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then - current_path="$( echo "${current_path}" | sed "s/^~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/")" - fi - typeset -AH dir_states dir_states=( "DEFAULT" "FOLDER_ICON" @@ -865,6 +859,34 @@ prompt_dir() { elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER" fi + + local bd dir_state_foreground dir_state_user_foreground + [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" ]] && bd="%B" || bd="" + + local dir_state_user_foreground="POWERLEVEL9K_DIR_${current_state}_FOREGROUND" + local dir_state_foreground="${(P)dir_state_user_foreground}" + [[ -z "${dir_state_foreground}" ]] && dir_state_foreground="${DEFAULT_COLOR}" + + if [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}" ]]; then + if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}" + else + current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}" + fi + fi + + if [[ -n "${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}" && $path_opt != "/" ]]; then + current_path="$( echo "${current_path}" | sed "s/\//%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}\/%F{$dir_state_foreground}/g")" + fi + + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then + current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" + fi + + if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + current_path="$( echo "${current_path}" | sed "s/~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/1")" + fi + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" } From 8b8dcb20663e56c09ea12d7743a8a139a339cc56 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 10 Feb 2018 15:41:40 +0400 Subject: [PATCH 04/64] Last dir bold - missed reset Missed the bold reset code `%b` in the logic, which caused everthing after the last dir to be bold, including the command line entry. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index faaa32ec..e7d3f1f1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -869,7 +869,7 @@ prompt_dir() { if [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}" ]]; then if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then - current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}" + current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" else current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}" fi From cd1387f530450889c386ab48b7076987eadbff06 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 07:17:50 +0400 Subject: [PATCH 05/64] Fixed reset bold on last dir missing. Missed the `%b` on making the last dir bold which leaked into the command prompt. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e7d3f1f1..fe660bc5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -871,7 +871,7 @@ prompt_dir() { if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" else - current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}" + current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}%b" fi fi From 69e55a30b3a7b5a3f23c8567820c840d59b32244 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 07:40:09 +0400 Subject: [PATCH 06/64] 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/powerlevel9k.spec | 14 +++++++------- test/segments/dir.spec | 44 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 5f6b6f27..e3d571a0 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 %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + 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)" 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 %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + 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)" 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 %K{blue}%F{black} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + 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)" 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 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{black}/tmp%b%K{red}%F{black} %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 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{green%}icon-here%f %F{black}/tmp%b%K{blue}%F{black} %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 %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{green%}icon-here%f %F{red}/tmp%b%K{blue}%F{black} %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 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}icon-here%f %F{black}/tmp%b%K{blue}%F{black} %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 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 From 1949fa7b9ee0e9663eb845b964ae77c851d1fd6e Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 07:48:22 +0400 Subject: [PATCH 07/64] Added set_default for bold dir segment Added `set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false` --- powerlevel9k.zsh-theme | 1 + 1 file changed, 1 insertion(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index fe660bc5..0a2d4cd8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -718,6 +718,7 @@ prompt_command_execution_time() { # Dir: current working directory set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" +set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # Parameters: # * $1 Alignment: string - left|right # * $2 Index: integer From e644ad640e41f9023096e80a77191bab9e5792d6 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 07:53:09 +0400 Subject: [PATCH 08/64] Changed testing for bold last dir --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0a2d4cd8..3681fbbf 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -862,7 +862,7 @@ prompt_dir() { fi local bd dir_state_foreground dir_state_user_foreground - [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" ]] && bd="%B" || bd="" + [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" = "true" ]] && bd="%B" || bd="" local dir_state_user_foreground="POWERLEVEL9K_DIR_${current_state}_FOREGROUND" local dir_state_foreground="${(P)dir_state_user_foreground}" From 4d71e217e964e4954e5c572f7ea48b4269338c6c Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 16:31:30 +0400 Subject: [PATCH 09/64] Attempt to fix Travis error --- powerlevel9k.zsh-theme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3681fbbf..40620220 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -864,11 +864,11 @@ prompt_dir() { local bd dir_state_foreground dir_state_user_foreground [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" = "true" ]] && bd="%B" || bd="" - local dir_state_user_foreground="POWERLEVEL9K_DIR_${current_state}_FOREGROUND" - local dir_state_foreground="${(P)dir_state_user_foreground}" - [[ -z "${dir_state_foreground}" ]] && dir_state_foreground="${DEFAULT_COLOR}" + local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND + local dir_state_foreground=${(P)dir_state_user_foreground} + [[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}" - if [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}" ]]; then + if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" else @@ -876,7 +876,7 @@ prompt_dir() { fi fi - if [[ -n "${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}" && $path_opt != "/" ]]; then + if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} && $path_opt != "/" ]]; then current_path="$( echo "${current_path}" | sed "s/\//%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}\/%F{$dir_state_foreground}/g")" fi From 4ac02b0f1b92dae3710805fcbd60bca4af5315b0 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 16:38:16 +0400 Subject: [PATCH 10/64] Renamed $bd to $bld --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 40620220..c99da804 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -861,8 +861,8 @@ prompt_dir() { current_state="HOME_SUBFOLDER" fi - local bd dir_state_foreground dir_state_user_foreground - [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" = "true" ]] && bd="%B" || bd="" + local bld dir_state_foreground dir_state_user_foreground + [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" = "true" ]] && bld="%B" || bld="" local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND local dir_state_foreground=${(P)dir_state_user_foreground} @@ -870,9 +870,9 @@ prompt_dir() { if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then - current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" + current_path="$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" else - current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}%b" + current_path="$(dirname $current_path)/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}%b" fi fi From 5491ee35c33ac8321fa6e61f1c330a1731e5d689 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 11 Feb 2018 17:49:09 +0400 Subject: [PATCH 11/64] Updated logic in prompt_dir Added a case where there is no last dir foreground, but still bold. --- powerlevel9k.zsh-theme | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c99da804..e5429635 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -870,9 +870,15 @@ prompt_dir() { if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then - current_path="$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b" + current_path="$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b%F{$dir_state_foreground}" else - current_path="$(dirname $current_path)/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}%b" + current_path="$(dirname $current_path)/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%b%F{$dir_state_foreground}" + fi + else + if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + current_path="$bld%F{$dir_state_foreground}$current_path%b%F{$dir_state_foreground}" + else + current_path="%F{$dir_state_foreground}$(dirname $current_path)/$bld$(basename $current_path)%b%F{$dir_state_foreground}" fi fi From 536549ea6231dd1fb15077de6e90abd1809eff04 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 11:42:40 +0400 Subject: [PATCH 12/64] Parameter substitution instead of dirname/basename Replaced external calls to `dirname` and `basename` with paramater substitution. --- powerlevel9k.zsh-theme | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e5429635..4f313418 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -868,17 +868,21 @@ prompt_dir() { local dir_state_foreground=${(P)dir_state_user_foreground} [[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}" + local dir_name base_name + dir_name=${path_opt%/*} + base_name=${path_opt##*/} + if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then - if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + if [[ $path_opt == "/" || $path_opt == "~" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then current_path="$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}%b%F{$dir_state_foreground}" else - current_path="$(dirname $current_path)/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%b%F{$dir_state_foreground}" + current_path="${dir_name}/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b%F{$dir_state_foreground}" fi else - if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + if [[ $path_opt == "/" || $path_opt == "~" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then current_path="$bld%F{$dir_state_foreground}$current_path%b%F{$dir_state_foreground}" else - current_path="%F{$dir_state_foreground}$(dirname $current_path)/$bld$(basename $current_path)%b%F{$dir_state_foreground}" + current_path="%F{$dir_state_foreground}${dir_name}/$bld${base_name}%b%F{$dir_state_foreground}" fi fi From 7cca0876e241620199fa1c55c20164af952e310a Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 11:48:14 +0400 Subject: [PATCH 13/64] Fixed = instead of == inside [[]] line 865 Missed an = inside the test for highlighting the last dir of the working directory. Travis should work now *fingers crossed* --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4f313418..4de1fd94 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -862,7 +862,7 @@ prompt_dir() { fi 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="%B" || bld="" local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND local dir_state_foreground=${(P)dir_state_user_foreground} From 2e417ec510c7f6a26eb332691d9baf7d91e8362d Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 11:57:32 +0400 Subject: [PATCH 14/64] Explicitly test if DIR_OMIT_FIRST_CHARACTER = true Changed ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} to "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" Lines 876 & 882 --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4de1fd94..b682b0ea 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -873,13 +873,13 @@ prompt_dir() { base_name=${path_opt##*/} if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then - if [[ $path_opt == "/" || $path_opt == "~" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; 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%F{$dir_state_foreground}%b%F{$dir_state_foreground}" else current_path="${dir_name}/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b%F{$dir_state_foreground}" fi else - if [[ $path_opt == "/" || $path_opt == "~" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then current_path="$bld%F{$dir_state_foreground}$current_path%b%F{$dir_state_foreground}" else current_path="%F{$dir_state_foreground}${dir_name}/$bld${base_name}%b%F{$dir_state_foreground}" @@ -894,7 +894,7 @@ prompt_dir() { current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" fi - if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then + if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then current_path="$( echo "${current_path}" | sed "s/~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/1")" fi From 9c6330624e1597d337b9aae2dc8e350b5e90a87a Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 12:15:56 +0400 Subject: [PATCH 15/64] Cleaned up DIR_PATH_HIGHLIGHT code Removed double call to %F and changed $x variables to ${x} for consistency. --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b682b0ea..3454a673 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -874,15 +874,15 @@ 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%F{$dir_state_foreground}%b%F{$dir_state_foreground}" + current_path="${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}%b%F{$dir_state_foreground}" else - current_path="${dir_name}/$bld%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b%F{$dir_state_foreground}" + current_path="${dir_name}/${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b%F{$dir_state_foreground}" fi else if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="$bld%F{$dir_state_foreground}$current_path%b%F{$dir_state_foreground}" + current_path="${bld}${current_path}%b%F{$dir_state_foreground}" else - current_path="%F{$dir_state_foreground}${dir_name}/$bld${base_name}%b%F{$dir_state_foreground}" + current_path="${dir_name}/${bld}${base_name}%b%F{$dir_state_foreground}" fi fi From c71e735c7d0d39374cfe9952598482419eb40f53 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 12:33:36 +0400 Subject: [PATCH 16/64] More code cleaning (extra %F calls) --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3454a673..9fb280bf 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -874,15 +874,15 @@ 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%F{$dir_state_foreground}" + current_path="${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}%b" else - current_path="${dir_name}/${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b%F{$dir_state_foreground}" + current_path="${dir_name}/${bld}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}%b" fi else if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="${bld}${current_path}%b%F{$dir_state_foreground}" + current_path="${bld}${current_path}%b" else - current_path="${dir_name}/${bld}${base_name}%b%F{$dir_state_foreground}" + current_path="${dir_name}/${bld}${base_name}%b" fi fi From b6f20d1032496d296a5aed4e059f7001195fb3d5 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:18:35 +0400 Subject: [PATCH 17/64] Updating Travis tests for bold dir --- test/powerlevel9k.spec | 14 ++++----- test/segments/dir.spec | 64 +++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 30 deletions(-) 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 From 1e54872873270b89700c3f88783bdc301ba40e50 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:30:21 +0400 Subject: [PATCH 18/64] Added test for Home folder highlighting --- test/segments/dir.spec | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 From dba80dbee922fee79b8709ac7fa981867bed89c5 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 13:48:25 +0400 Subject: [PATCH 19/64] Added tests for other folder highlighing --- test/segments/dir.spec | 82 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) 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 From 276bc9017c99591cfdab373f659182c7e9166063 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 14:05:49 +0400 Subject: [PATCH 20/64] Updated testBoldRootSubsubdirWorks() Forgot to initialize the bolding variable --- test/segments/dir.spec | 2 ++ 1 file changed, 2 insertions(+) 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() { From 4fc4d157037bcef7d3c3610463dbbdb8b919a2c9 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Wed, 14 Feb 2018 14:17:50 +0400 Subject: [PATCH 21/64] Added tests for DIR_PATH_SEPARATOR_FOREGROUND --- test/segments/dir.spec | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) 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 From 64cbdaf4c2a61e30365dc0f12b672d57e879d2aa Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 17:36:36 +0400 Subject: [PATCH 22/64] Streamlined dir strategies Removed sed from `truncate_middle`, `truncate_from_right` and partially from `truncate_with_package_name` --- powerlevel9k.zsh-theme | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9fb280bf..f7d31002 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -724,15 +724,40 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # * $2 Index: integer prompt_dir() { local current_path="$(print -P "%~")" + local paths=(${(s:/:)PWD}) + local cur_path cur_short_path directory dir_length cur_dir + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then - set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' + set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") + cur_short_path='/' + local last_pos + local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) + for directory in ${paths[@]} + do + cur_dir=$directory + dir_length=${#cur_dir} + if (( $dir_length > $max_length )); then + last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} + fi + cur_short_path+="$cur_dir/" + done + current_path="${cur_short_path: : -1}" ;; truncate_from_right) - current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) + cur_short_path='/' + for directory in ${paths[@]} + do + cur_dir=$directory + if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER + fi + cur_short_path+="$cur_dir/" + done + current_path="${cur_short_path: : -1}" ;; truncate_with_package_name) local name repo_path package_path current_dir zero @@ -744,11 +769,11 @@ prompt_dir() { # Remove trailing slash from git path, so that we can # remove that git path from the pwd. gitPath=${gitPath%/} - package_path=${$(pwd)%%$gitPath} + package_path=${$current_path%%$gitPath} # Remove trailing slash package_path=${package_path%/} elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then - package_path=${$(pwd)%%/.git*} + package_path=${$current_path%%/.git*} fi # Replace the shortest possible match of the marked folder from @@ -757,11 +782,10 @@ prompt_dir() { # in the path (this is done by the "zero" pattern; see # http://stackoverflow.com/a/40855342/5586433). local zero='%([BSUbfksu]|([FB]|){*})' - current_dir=$(pwd) # Then, find the length of the package_path string, and save the # subdirectory path as a substring of the current directory's path from 0 # to the length of the package path's string - subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}") + subdirectory_path=$(truncatePathFromRight "${current_path:${#${(S%%)package_path//$~zero/}}}") # Parse the 'name' from the package.json; if there are any problems, just # print the file path defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) @@ -815,7 +839,6 @@ prompt_dir() { truncate_to_unique) # for each parent path component find the shortest unique beginning # characters sequence. Source: https://stackoverflow.com/a/45336078 - paths=(${(s:/:)PWD}) cur_path='/' cur_short_path='/' for directory in ${paths[@]} From 110f54f7e2d38c0f59ea25fcc947144e317382f1 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 18:12:07 +0400 Subject: [PATCH 23/64] Added edge case tests for ~ and / Fixed edge cases --- powerlevel9k.zsh-theme | 77 +++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f7d31002..2f63b486 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -723,8 +723,9 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # * $1 Alignment: string - left|right # * $2 Index: integer prompt_dir() { - local current_path="$(print -P "%~")" - local paths=(${(s:/:)PWD}) + local current_dir="$(print -P "%~")" + local paths + [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) || paths[0] = "/" local cur_path cur_short_path directory dir_length cur_dir if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then @@ -732,32 +733,40 @@ prompt_dir() { case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - cur_short_path='/' - local last_pos - local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) - for directory in ${paths[@]} - do - cur_dir=$directory - dir_length=${#cur_dir} - if (( $dir_length > $max_length )); then - last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} - fi - cur_short_path+="$cur_dir/" - done - current_path="${cur_short_path: : -1}" + if [[ $current_dir != "/" ]]; then + [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' + local last_pos + local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) + for directory in ${paths[@]} + do + cur_dir=$directory + dir_length=${#cur_dir} + if (( $dir_length > $max_length )); then + last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} + fi + cur_short_path+="$cur_dir/" + done + current_path="${cur_short_path: : -1}" + else + current_path="/" + fi ;; truncate_from_right) - cur_short_path='/' - for directory in ${paths[@]} - do - cur_dir=$directory - if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER - fi - cur_short_path+="$cur_dir/" - done - current_path="${cur_short_path: : -1}" + if [[ $current_dir != "/" ]]; then + [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' + for directory in ${paths[@]} + do + cur_dir=$directory + if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER + fi + cur_short_path+="$cur_dir/" + done + current_path="${cur_short_path: : -1}" + else + current_path="/" + fi ;; truncate_with_package_name) local name repo_path package_path current_dir zero @@ -769,11 +778,11 @@ prompt_dir() { # Remove trailing slash from git path, so that we can # remove that git path from the pwd. gitPath=${gitPath%/} - package_path=${$current_path%%$gitPath} + package_path=${current_dir%%$gitPath} # Remove trailing slash - package_path=${package_path%/} + package_path=${package_dir%/} elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then - package_path=${$current_path%%/.git*} + package_path=${current_dir%%/.git*} fi # Replace the shortest possible match of the marked folder from @@ -785,7 +794,7 @@ prompt_dir() { # Then, find the length of the package_path string, and save the # subdirectory path as a substring of the current directory's path from 0 # to the length of the package path's string - subdirectory_path=$(truncatePathFromRight "${current_path:${#${(S%%)package_path//$~zero/}}}") + subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}") # Parse the 'name' from the package.json; if there are any problems, just # print the file path defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) @@ -807,7 +816,7 @@ prompt_dir() { # from the package.json and append the current subdirectory current_path="`echo $packageName | tr -d '"'`$subdirectory_path" else - current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) + current_path=$(truncatePathFromRight ${current_path//$HOME/"~"} ) fi ;; truncate_with_folder_marker) @@ -834,7 +843,7 @@ prompt_dir() { # Replace the shortest possible match of the marked folder from # the current path. - current_path=$current_path${PWD#${last_marked_folder}*} + current_path=$current_path${current_dir#${last_marked_folder}*} ;; truncate_to_unique) # for each parent path component find the shortest unique beginning @@ -878,9 +887,9 @@ prompt_dir() { local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ $(print -P "%~") == '~' ]]; then + elif [[ $current_dir == '~' ]]; then current_state="HOME" - elif [[ $(print -P "%~") == '~'* ]]; then + elif [[ $current_dir == '~'* ]]; then current_state="HOME_SUBFOLDER" fi From ad4b284e56244842c69e5e99aac4d5626c10a542 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 18:26:11 +0400 Subject: [PATCH 24/64] Fixed accidentally truncating current folder too --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2f63b486..4abee3b4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -725,7 +725,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_dir="$(print -P "%~")" local paths - [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) || paths[0] = "/" + [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) local cur_path cur_short_path directory dir_length cur_dir if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then @@ -741,7 +741,7 @@ prompt_dir() { do cur_dir=$directory dir_length=${#cur_dir} - if (( $dir_length > $max_length )); then + if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} fi @@ -758,7 +758,7 @@ prompt_dir() { for directory in ${paths[@]} do cur_dir=$directory - if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then + if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH && [[ $cur_dir != $paths[${#paths}] ]]; then cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER fi cur_short_path+="$cur_dir/" From 29620f3d8187a6160950289dda72bb30bf040873 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 18:39:39 +0400 Subject: [PATCH 25/64] Accidentally deleted )) which threw an error --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4abee3b4..0c7292a3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -758,7 +758,7 @@ prompt_dir() { for directory in ${paths[@]} do cur_dir=$directory - if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH && [[ $cur_dir != $paths[${#paths}] ]]; then + if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) && [[ $cur_dir != $paths[${#paths}] ]]; then cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER fi cur_short_path+="$cur_dir/" From b73af072c1b0dd4bce84185c5374054e5dcb70df Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 18:54:43 +0400 Subject: [PATCH 26/64] Fixed truncate_from_right to incl length of delim Updated length test to include delimiter length. Added comments --- powerlevel9k.zsh-theme | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0c7292a3..ecca1f38 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -725,7 +725,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_dir="$(print -P "%~")" local paths - [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) + [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) # only split if not root folder local cur_path cur_short_path directory dir_length cur_dir if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then @@ -733,37 +733,37 @@ prompt_dir() { case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - if [[ $current_dir != "/" ]]; then - [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' + if [[ $current_dir != "/" ]]; then # root is an exception and won't have paths + [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' # if we are in the $HOME folder, we don't need starting / local last_pos - local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) - for directory in ${paths[@]} + local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) # has to be double the length for beginning / end count + for directory in ${paths[@]} # go through all the paths do cur_dir=$directory dir_length=${#cur_dir} - if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then + if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} fi cur_short_path+="$cur_dir/" done - current_path="${cur_short_path: : -1}" + current_path="${cur_short_path: : -1}" # remove trailing slash else current_path="/" fi ;; truncate_from_right) - if [[ $current_dir != "/" ]]; then - [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' + if [[ $current_dir != "/" ]]; then # root is an exception and won't have paths + [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' # if we are in the $HOME folder, we don't need starting / for directory in ${paths[@]} do cur_dir=$directory - if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) && [[ $cur_dir != $paths[${#paths}] ]]; then + if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER fi cur_short_path+="$cur_dir/" done - current_path="${cur_short_path: : -1}" + current_path="${cur_short_path: : -1}" # remove trailing slash else current_path="/" fi From 728aa0ec387ab12644f905b5b88cc5638b9da810 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 20:42:35 +0400 Subject: [PATCH 27/64] Updated previous test as Travis still fails --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ecca1f38..c6c17c86 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -758,7 +758,7 @@ prompt_dir() { for directory in ${paths[@]} do cur_dir=$directory - if (( ${#cur_dir} > $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + if (( ${#cur_dir} > ( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} ) )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER fi cur_short_path+="$cur_dir/" From 9a3dd6bf253a5cd1171d06e6c74a537423e4bebb Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sat, 17 Feb 2018 21:09:27 +0400 Subject: [PATCH 28/64] Fix issue with SHORTEN_DELIM If `$POWERLEVEL9K_SHORTEN_DELIMITER` is a unicode escape sequence, its length is 6 instead of 1. Added variable to hold actual character(s) --- powerlevel9k.zsh-theme | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c6c17c86..d5db242f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -730,6 +730,7 @@ prompt_dir() { if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026' + local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character if required case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) @@ -743,7 +744,7 @@ prompt_dir() { dir_length=${#cur_dir} if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim${cur_dir:$last_pos:$dir_length} fi cur_short_path+="$cur_dir/" done @@ -758,8 +759,10 @@ prompt_dir() { for directory in ${paths[@]} do cur_dir=$directory - if (( ${#cur_dir} > ( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} ) )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER + dir_length=${#cur_dir} + local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) + if (( $dir_length > $threshhold )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim fi cur_short_path+="$cur_dir/" done From 4f1da4a64dcbd0923d591ffda50ce1f5d2870ce2 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 16:22:59 +0400 Subject: [PATCH 29/64] Changed current_dir - Test Travis response --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d5db242f..2e483844 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -723,13 +723,14 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # * $1 Alignment: string - left|right # * $2 Index: integer prompt_dir() { - local current_dir="$(print -P "%~")" + local current_dir="$(echo $PWD)" + current_dir=${current_dir//$HOME/"~"} local paths [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) # only split if not root folder local cur_path cur_short_path directory dir_length cur_dir if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then - set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026' + set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character if required case "$POWERLEVEL9K_SHORTEN_STRATEGY" in From b1b0ad949a0ee558fa6b6c25882b961c8200a9eb Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 16:29:05 +0400 Subject: [PATCH 30/64] Updated truncate_from_right test --- powerlevel9k.zsh-theme | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2e483844..0f6461c3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -723,8 +723,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # * $1 Alignment: string - left|right # * $2 Index: integer prompt_dir() { - local current_dir="$(echo $PWD)" - current_dir=${current_dir//$HOME/"~"} + local current_dir="$(print -P '%~')" local paths [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) # only split if not root folder local cur_path cur_short_path directory dir_length cur_dir @@ -762,7 +761,7 @@ prompt_dir() { cur_dir=$directory dir_length=${#cur_dir} local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( $dir_length > $threshhold )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + if (( ( $dir_length + 1) > $threshhold )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim fi cur_short_path+="$cur_dir/" From 8180d724efd4e7f97808429d3ea12cec585a7465 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 16:35:07 +0400 Subject: [PATCH 31/64] Added test for dir_length == trunc_length --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0f6461c3..6572b2d0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -761,7 +761,7 @@ prompt_dir() { cur_dir=$directory dir_length=${#cur_dir} local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( ( $dir_length + 1) > $threshhold )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + if (( ( $dir_length > $threshhold )) && [[ !c $dir_length == $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim fi cur_short_path+="$cur_dir/" From 97d4e2877db2bb5e63479e2f987ce475a26d9d0a Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 16:56:32 +0400 Subject: [PATCH 32/64] Fixed typo --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6572b2d0..5a322a57 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -761,7 +761,7 @@ prompt_dir() { cur_dir=$directory dir_length=${#cur_dir} local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( ( $dir_length > $threshhold )) && [[ !c $dir_length == $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + if (( ( $dir_length > $threshhold )) && [[ ! $dir_length == $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim fi cur_short_path+="$cur_dir/" From 0acdc4e03231293327269b87aabc2d337ed474d0 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 16:58:06 +0400 Subject: [PATCH 33/64] Fixed another typo - shouldn't code when sick :p --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5a322a57..1589cf3d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -761,7 +761,7 @@ prompt_dir() { cur_dir=$directory dir_length=${#cur_dir} local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( ( $dir_length > $threshhold )) && [[ ! $dir_length == $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + if (( $dir_length > $threshhold )) && [[ $dir_length != $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim fi cur_short_path+="$cur_dir/" From 38d7e60ae3f9efd5f4a81d52b5ce6046b0416b8b Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 18:36:18 +0400 Subject: [PATCH 34/64] Rewrote trunc middle/right to use for loop --- powerlevel9k.zsh-theme | 88 ++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1589cf3d..c0820475 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -723,52 +723,44 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # * $1 Alignment: string - left|right # * $2 Index: integer prompt_dir() { - local current_dir="$(print -P '%~')" - local paths - [[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) # only split if not root folder - local cur_path cur_short_path directory dir_length cur_dir - + local current_path="$(print -P '%~')" + 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 set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" - local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character if required + local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - if [[ $current_dir != "/" ]]; then # root is an exception and won't have paths - [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' # if we are in the $HOME folder, we don't need starting / - local last_pos + if (( ${#paths} > 0 )); then # root is an exception and won't have paths local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) # has to be double the length for beginning / end count - for directory in ${paths[@]} # go through all the paths - do - cur_dir=$directory - dir_length=${#cur_dir} - if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path + local last_pos + for (( i=1; i<${#paths}; i++ )); do + test_dir=$paths[$i] + test_dir_length=${#test_dir} + if (( $test_dir_length > $max_length )); then # only shorten if long enough last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim${cur_dir:$last_pos:$dir_length} + trunc_path+="${test_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim${test_dir:$last_pos:$test_dir_length}/" + else + trunc_path+="${test_dir}/" fi - cur_short_path+="$cur_dir/" done - current_path="${cur_short_path: : -1}" # remove trailing slash - else - current_path="/" + current_path=$trunc_path${current_path:t} fi ;; truncate_from_right) - if [[ $current_dir != "/" ]]; then # root is an exception and won't have paths - [[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/' # if we are in the $HOME folder, we don't need starting / - for directory in ${paths[@]} - do - cur_dir=$directory - dir_length=${#cur_dir} - local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( $dir_length > $threshhold )) && [[ $dir_length != $POWERLEVEL9K_SHORTEN_DIR_LENGTH && $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path - cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim + if (( ${#paths} > 0 )); then # root is an exception and won't have paths + for (( i=1; i<${#paths}; i++ )); do + test_dir="$paths[$i]" + test_dir_length=${#test_dir} + threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) + if (( $test_dir_length > $threshhold )); then # only shorten if long enough + trunc_path+="${test_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim/" + else + trunc_path+="${test_dir}/" fi - cur_short_path+="$cur_dir/" done - current_path="${cur_short_path: : -1}" # remove trailing slash - else - current_path="/" + current_path=$trunc_path${current_path:t} fi ;; truncate_with_package_name) @@ -851,22 +843,24 @@ prompt_dir() { truncate_to_unique) # for each parent path component find the shortest unique beginning # characters sequence. Source: https://stackoverflow.com/a/45336078 - cur_path='/' - cur_short_path='/' - for directory in ${paths[@]} - do - cur_dir='' - for (( i=0; i<${#directory}; i++ )); do - cur_dir+="${directory:$i:1}" - matching=("$cur_path"/"$cur_dir"*/) - if [[ ${#matching[@]} -eq 1 ]]; then - break - fi + if (( ${#paths} > 0 )); then # root is an exception 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 - cur_short_path+="$cur_dir/" - cur_path+="$directory/" - done - current_path="${cur_short_path: : -1}" + current_path="${trunc_path: : -1}" + fi ;; *) current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" From 9f87bd5654bcf7ed28abdc20109368cf1cc130e4 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 19:05:37 +0400 Subject: [PATCH 35/64] Added / for non-home folders --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c0820475..53f115c3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -732,6 +732,7 @@ prompt_dir() { case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) + [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' if (( ${#paths} > 0 )); then # root is an exception and won't have paths local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) # has to be double the length for beginning / end count local last_pos @@ -749,6 +750,7 @@ prompt_dir() { fi ;; truncate_from_right) + [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' if (( ${#paths} > 0 )); then # root is an exception and won't have paths for (( i=1; i<${#paths}; i++ )); do test_dir="$paths[$i]" From 3b182d2eb6f97da5731ba543a2486622d6cfd287 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 22:35:20 +0400 Subject: [PATCH 36/64] Updated code for testing --- powerlevel9k.zsh-theme | 106 ++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 53f115c3..70aca115 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -756,7 +756,7 @@ prompt_dir() { test_dir="$paths[$i]" test_dir_length=${#test_dir} threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( $test_dir_length > $threshhold )); then # only shorten if long enough + if (( $test_dir_length > $threshhold && $test_dir_length > 3 )); then # only shorten if long enough trunc_path+="${test_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim/" else trunc_path+="${test_dir}/" @@ -765,57 +765,6 @@ prompt_dir() { current_path=$trunc_path${current_path:t} fi ;; - truncate_with_package_name) - local name repo_path package_path current_dir zero - - # Get the path of the Git repo, which should have the package.json file - if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then - # Get path from the root of the git repository to the current dir - local gitPath=$(git rev-parse --show-prefix) - # Remove trailing slash from git path, so that we can - # remove that git path from the pwd. - gitPath=${gitPath%/} - package_path=${current_dir%%$gitPath} - # Remove trailing slash - package_path=${package_dir%/} - elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then - package_path=${current_dir%%/.git*} - fi - - # Replace the shortest possible match of the marked folder from - # the current path. Remove the amount of characters up to the - # folder marker from the left. Count only the visible characters - # in the path (this is done by the "zero" pattern; see - # http://stackoverflow.com/a/40855342/5586433). - local zero='%([BSUbfksu]|([FB]|){*})' - # Then, find the length of the package_path string, and save the - # subdirectory path as a substring of the current directory's path from 0 - # to the length of the package path's string - subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}") - # Parse the 'name' from the package.json; if there are any problems, just - # print the file path - defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) - - local pkgFile="unknown" - for file in "${POWERLEVEL9K_DIR_PACKAGE_FILES[@]}"; do - if [[ -f "${package_path}/${file}" ]]; then - pkgFile="${package_path}/${file}" - break; - fi - done - - local packageName=$(jq '.name' ${pkgFile} 2> /dev/null \ - || node -e 'console.log(require(process.argv[1]).name);' ${pkgFile} 2>/dev/null \ - || cat "${pkgFile}" 2> /dev/null | grep -m 1 "\"name\"" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}' 2>/dev/null \ - ) - if [[ -n "${packageName}" ]]; then - # Instead of printing out the full path, print out the name of the package - # from the package.json and append the current subdirectory - current_path="`echo $packageName | tr -d '"'`$subdirectory_path" - else - current_path=$(truncatePathFromRight ${current_path//$HOME/"~"} ) - fi - ;; truncate_with_folder_marker) local last_marked_folder marked_folder set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" @@ -840,7 +789,58 @@ prompt_dir() { # Replace the shortest possible match of the marked folder from # the current path. - current_path=$current_path${current_dir#${last_marked_folder}*} + current_path=$current_path${current_path#${last_marked_folder}*} + ;; + truncate_with_package_name) + local name repo_path package_path current_dir zero + + # Get the path of the Git repo, which should have the package.json file + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then + # Get path from the root of the git repository to the current dir + local gitPath=$(git rev-parse --show-prefix) + # Remove trailing slash from git path, so that we can + # remove that git path from the pwd. + gitPath=${gitPath%/} + package_path=${current_path%%$gitPath} + # Remove trailing slash + package_path=${package_dir%/} + elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then + package_path=${current_path%%/.git*} + fi + + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' + # Then, find the length of the package_path string, and save the + # subdirectory path as a substring of the current directory's path from 0 + # to the length of the package path's string + subdirectory_path=$(truncatePathFromRight "${current_path:${#${(S%%)package_path//$~zero/}}}") + # Parse the 'name' from the package.json; if there are any problems, just + # print the file path + defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) + + local pkgFile="unknown" + for file in "${POWERLEVEL9K_DIR_PACKAGE_FILES[@]}"; do + if [[ -f "${package_path}/${file}" ]]; then + pkgFile="${package_path}/${file}" + break; + fi + done + + local packageName=$(jq '.name' ${pkgFile} 2> /dev/null \ + || node -e 'console.log(require(process.argv[1]).name);' ${pkgFile} 2>/dev/null \ + || cat "${pkgFile}" 2> /dev/null | grep -m 1 "\"name\"" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}' 2>/dev/null \ + ) + if [[ -n "${packageName}" ]]; then + # Instead of printing out the full path, print out the name of the package + # from the package.json and append the current subdirectory + current_path="`echo $packageName | tr -d '"'`$subdirectory_path" + else + current_path=$(truncatePathFromRight ${current_path//$HOME/"~"} ) + fi ;; truncate_to_unique) # for each parent path component find the shortest unique beginning From fb09d753915ff193f4896db0b74a1b67aef2cfa4 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Sun, 18 Feb 2018 22:56:52 +0400 Subject: [PATCH 37/64] Updated truncate_to_unique --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 70aca115..fcd1ab98 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -725,7 +725,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" 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 + (( ${#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 set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character @@ -861,7 +861,8 @@ prompt_dir() { trunc_path+="$test_dir/" cur_path+="$directory/" done - current_path="${trunc_path: : -1}" + [[ $current_path == "~"* ]] && current_path="~/" || current_path="" + current_path+="${trunc_path: : -1}" fi ;; *) From 58342612eb8ac178e53779224eb6fd00bb7a4649 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 16:05:58 +0400 Subject: [PATCH 38/64] Improved truncation code --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index fcd1ab98..36a641d8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -861,8 +861,8 @@ prompt_dir() { trunc_path+="$test_dir/" cur_path+="$directory/" done - [[ $current_path == "~"* ]] && current_path="~/" || current_path="" - current_path+="${trunc_path: : -1}" + [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path" + current_path="${trunc_path: : -1}" fi ;; *) From 21b7749075a2af48dd52dcd93e3d3d4f8e63d0c4 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 22:00:15 +0400 Subject: [PATCH 39/64] Added truncatePath to utilities.zsh Added `function truncatePath()` to utilities.zsh to take care of truncation. This is pure zsh code, without calls to `sed`. Parameters are: * $1 Path: string - the directory path to be truncated * $2 Length: integer - length to truncate to * $3 Delimiter: string - the delimiter to use * $4 From: string - "right" | "middle". If omited, assumes right. Cleaned up code to use the new function instead. --- functions/utilities.zsh | 75 ++++++++++++++++++++++++++++++++ powerlevel9k.zsh-theme | 95 +++++++++++++++-------------------------- 2 files changed, 109 insertions(+), 61 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index b4bfb838..9f1ea53e 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -213,6 +213,81 @@ function segmentShouldBeJoined() { fi } +################################################################ +# Given a directory path, truncate it according to the settings. +# Parameters: +# * $1 Path: string - the directory path to be truncated +# * $2 Length: integer - length to truncate to +# * $3 Delimiter: string - the delimiter to use +# * $4 From: string - "right" | "middle". If omited, assumes right. +function truncatePath() { + # if the current path is not 1 character long (e.g. "/" or "~") + if (( ${#1} > 1 )); then + # convert $2 from string to integer + 2=$(( $2 )) + # set $3 to "" if not defined + [[ -z $3 ]] && local 3="" || 3=$(echo -n $3) + # set $4 to "right" if not defined + [[ -z $4 ]] && 4="right" + # create a variable for the truncated path. + local trunc_path + # if the path is in the home folder, don't add a "/" to the start + [[ $1 != "~"* ]] && trunc_path='/' || trunc_path='' + # split the path into an array using "/" as the delimiter and remove "~/" + local paths=(${(s:/:)1}) + # declare locals for the directory being tested and its length + local test_dir test_dir_length + # do the needed truncation + case $4 in + right) + # include the delimiter length in the threshhold + local threshhold=$(( $2 + ${#3} )) + # loop through the paths + for (( i=1; i<${#paths}; i++ )); do + # get the current directory value + test_dir=$paths[$i] + test_dir_length=${#test_dir} + # only truncate if the resulting truncation will be shorter than + # the truncation + delimiter length and at least 3 characters + if (( $test_dir_length > $threshhold )) && (( $test_dir_length > 3 )); then + # use the first $2 characters and the delimiter + trunc_path+="${test_dir:0:$2}$3/" + else + # use the full path + trunc_path+="${test_dir}/" + fi + done + ;; + middle) + # we need double the length for start and end truncation + delimiter length + local threshhold=$(( $2 * 2 + ${#3} )) + # create a variable for the start of the end truncation + local last_pos + # loop through the paths + for (( i=1; i<${#paths}; i++ )); do + # get the current directory value + test_dir=$paths[$i] + test_dir_length=${#test_dir} + # only truncate if the resulting truncation will be shorter than + # the truncation + delimiter length + if (( $test_dir_length > $threshhold + ${#3} )); then + # use the first $2 characters, the delimiter and the last $2 characters + last_pos=$(( $test_dir_length - $2 )) + trunc_path+="${test_dir:0:$2}$3${test_dir:$last_pos:$test_dir_length}/" + else + # use the full path + trunc_path+="${test_dir}/" + fi + done + ;; + esac + # return the truncated path + the current directory + echo $trunc_path${1:t} + else # current path is 1 character long (e.g. "/" or "~") + echo $1 + fi +} + # Given a directory path, truncate it according to the settings for # `truncate_from_right` function truncatePathFromRight() { diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 36a641d8..64682fa3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -716,12 +716,12 @@ prompt_command_execution_time() { ################################################################ # Dir: current working directory -set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" -set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" -set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false # Parameters: # * $1 Alignment: string - left|right # * $2 Index: integer +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 '%~')" local paths directory test_dir test_dir_length trunc_path threshhold @@ -732,64 +732,38 @@ prompt_dir() { case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' - if (( ${#paths} > 0 )); then # root is an exception and won't have paths - local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 )) # has to be double the length for beginning / end count - local last_pos - for (( i=1; i<${#paths}; i++ )); do - test_dir=$paths[$i] - test_dir_length=${#test_dir} - if (( $test_dir_length > $max_length )); then # only shorten if long enough - last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) - trunc_path+="${test_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim${test_dir:$last_pos:$test_dir_length}/" - else - trunc_path+="${test_dir}/" - fi - done - current_path=$trunc_path${current_path:t} - fi + current_path=$(truncatePath $current_path $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER "middle") ;; truncate_from_right) - [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' - if (( ${#paths} > 0 )); then # root is an exception and won't have paths - for (( i=1; i<${#paths}; i++ )); do - test_dir="$paths[$i]" - test_dir_length=${#test_dir} - threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} )) - if (( $test_dir_length > $threshhold && $test_dir_length > 3 )); then # only shorten if long enough - trunc_path+="${test_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim/" - else - trunc_path+="${test_dir}/" - fi - done - current_path=$trunc_path${current_path:t} - fi + current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) ;; truncate_with_folder_marker) - local last_marked_folder marked_folder - set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + if (( ${#paths} > 0 )); then # root is an exception and won't have paths + local last_marked_folder marked_folder + set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" - # Search for the folder marker in the parent directories and - # buildup a pattern that is removed from the current path - # later on. - for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do - if [[ "$marked_folder" == "/" ]]; then - # If we reached root folder, stop upsearch. - current_path="/" - elif [[ "$marked_folder" == "$HOME" ]]; then - # If we reached home folder, stop upsearch. - current_path="~" - elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then - current_path="${current_path%/}/${marked_folder##*/}" - else - current_path="${current_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" - fi - last_marked_folder=$marked_folder - done + # Search for the folder marker in the parent directories and + # buildup a pattern that is removed from the current path + # later on. + for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do + if [[ "$marked_folder" == "/" ]]; then + # If we reached root folder, stop upsearch. + trunc_path="/" + elif [[ "$marked_folder" == "$HOME" ]]; then + # If we reached home folder, stop upsearch. + trunc_path="~" + elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then + trunc_path="${trunc_path%/}/${marked_folder##*/}" + else + trunc_path="${trunc_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" + fi + last_marked_folder=$marked_folder + done - # Replace the shortest possible match of the marked folder from - # the current path. - current_path=$current_path${current_path#${last_marked_folder}*} + # Replace the shortest possible match of the marked folder from + # the current path. + current_path=$trunc_path${current_path#${last_marked_folder}*} + fi ;; truncate_with_package_name) local name repo_path package_path current_dir zero @@ -801,11 +775,11 @@ prompt_dir() { # Remove trailing slash from git path, so that we can # remove that git path from the pwd. gitPath=${gitPath%/} - package_path=${current_path%%$gitPath} + package_path=${$(pwd)%%$gitPath} # Remove trailing slash - package_path=${package_dir%/} + package_path=${package_path%/} elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then - package_path=${current_path%%/.git*} + package_path=${$(pwd)%%/.git*} fi # Replace the shortest possible match of the marked folder from @@ -814,10 +788,11 @@ prompt_dir() { # in the path (this is done by the "zero" pattern; see # http://stackoverflow.com/a/40855342/5586433). local zero='%([BSUbfksu]|([FB]|){*})' + trunc_path=$(pwd) # Then, find the length of the package_path string, and save the # subdirectory path as a substring of the current directory's path from 0 # to the length of the package path's string - subdirectory_path=$(truncatePathFromRight "${current_path:${#${(S%%)package_path//$~zero/}}}") + subdirectory_path=$(truncatePath "${trunc_path:${#${(S%%)package_path//$~zero/}}}" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) # Parse the 'name' from the package.json; if there are any problems, just # print the file path defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) @@ -838,8 +813,6 @@ prompt_dir() { # Instead of printing out the full path, print out the name of the package # from the package.json and append the current subdirectory current_path="`echo $packageName | tr -d '"'`$subdirectory_path" - else - current_path=$(truncatePathFromRight ${current_path//$HOME/"~"} ) fi ;; truncate_to_unique) From 115b656790bffef629539cc1d90c78502ad8606d Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 22:08:06 +0400 Subject: [PATCH 40/64] Forgot to update code when creating new func --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 64682fa3..682fbf3d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -724,6 +724,7 @@ set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" + local num_paths=(${(s:/:)current_path}) 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 @@ -738,7 +739,7 @@ prompt_dir() { current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) ;; truncate_with_folder_marker) - if (( ${#paths} > 0 )); then # root is an exception and won't have paths + if (( ${#num_paths} > 0 )); then # root is an exception and won't have paths local last_marked_folder marked_folder set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" @@ -818,7 +819,7 @@ prompt_dir() { truncate_to_unique) # for each parent path component find the shortest unique beginning # characters sequence. Source: https://stackoverflow.com/a/45336078 - if (( ${#paths} > 0 )); then # root is an exception and won't have paths + if (( ${#num_paths} > 0 )); then # root is an exception and won't have paths local matching local cur_path='/' [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' From a699393d58c1e9228dadd95e42ccf54f1b687dd2 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 22:12:16 +0400 Subject: [PATCH 41/64] Fixed error in coding Shouldn't code when tired lol. --- powerlevel9k.zsh-theme | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 682fbf3d..5357dab6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -724,9 +724,8 @@ set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" - local num_paths=(${(s:/:)current_path}) 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 + (( ${#current_path} > 1 )) && num_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 set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character From 4996e955e02108eadcb57a5cc1e181dd2c008734 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 22:18:59 +0400 Subject: [PATCH 42/64] Updated path splitting line Works in the console, but Travis doesn't like it. --- functions/utilities.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 9f1ea53e..a539fc6e 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -234,7 +234,7 @@ function truncatePath() { # if the path is in the home folder, don't add a "/" to the start [[ $1 != "~"* ]] && trunc_path='/' || trunc_path='' # split the path into an array using "/" as the delimiter and remove "~/" - local paths=(${(s:/:)1}) + local paths=(${(s:/:)${1}}) # declare locals for the directory being tested and its length local test_dir test_dir_length # do the needed truncation From 04726d21ef4acb46cd995eb21ad631632a09f6ff Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 23:52:07 +0400 Subject: [PATCH 43/64] Changed path splitting to test Travis --- functions/utilities.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index a539fc6e..c59652f5 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -232,9 +232,9 @@ function truncatePath() { # create a variable for the truncated path. local trunc_path # if the path is in the home folder, don't add a "/" to the start - [[ $1 != "~"* ]] && trunc_path='/' || trunc_path='' - # split the path into an array using "/" as the delimiter and remove "~/" - local paths=(${(s:/:)${1}}) + [[ $1 == "~"* ]] && trunc_path='' || trunc_path='/' + # split the path into an array using "/" as the delimiter + local paths=(${(s:/:)1}) # declare locals for the directory being tested and its length local test_dir test_dir_length # do the needed truncation From f10a7daab02af4b23e161627bba3850823f3b678 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Mon, 19 Feb 2018 23:59:41 +0400 Subject: [PATCH 44/64] Another change to test Travis --- functions/utilities.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index c59652f5..5babee2f 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -231,10 +231,10 @@ function truncatePath() { [[ -z $4 ]] && 4="right" # create a variable for the truncated path. local trunc_path - # if the path is in the home folder, don't add a "/" to the start - [[ $1 == "~"* ]] && trunc_path='' || trunc_path='/' + # if the path is in the home folder, add "~/" to the start otherwise "/" + [[ $1 == "~"* ]] && trunc_path='~/' || trunc_path='/' # split the path into an array using "/" as the delimiter - local paths=(${(s:/:)1}) + local paths=(${(s:/:)${1//"~\/"/}}) # declare locals for the directory being tested and its length local test_dir test_dir_length # do the needed truncation From d31ac26caa359c867f2f82d6fbfee2bb72cf22cc Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Tue, 20 Feb 2018 01:14:06 +0400 Subject: [PATCH 45/64] Another Travis test --- functions/utilities.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 5babee2f..fb1cc276 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -234,7 +234,8 @@ function truncatePath() { # if the path is in the home folder, add "~/" to the start otherwise "/" [[ $1 == "~"* ]] && trunc_path='~/' || trunc_path='/' # split the path into an array using "/" as the delimiter - local paths=(${(s:/:)${1//"~\/"/}}) + local paths=$1 + paths=(${(s:/:)${paths//"~\/"/}}) # declare locals for the directory being tested and its length local test_dir test_dir_length # do the needed truncation From 2214124327849f51b3e78d2eacb0cd77e117fed7 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:17:26 +0400 Subject: [PATCH 46/64] Updated truncatePath() Added variable `delim_len` with test when delim="" --- functions/utilities.zsh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index fb1cc276..7dee844c 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -234,15 +234,16 @@ function truncatePath() { # if the path is in the home folder, add "~/" to the start otherwise "/" [[ $1 == "~"* ]] && trunc_path='~/' || trunc_path='/' # split the path into an array using "/" as the delimiter - local paths=$1 - paths=(${(s:/:)${paths//"~\/"/}}) + local paths=(${(s:/:)${1//"~\/"/}}) # declare locals for the directory being tested and its length - local test_dir test_dir_length + local test_dir test_dir_length delim_len # do the needed truncation case $4 in right) + # check the length of the delimiter + [[ -z $3 ]] && delim_len=${#3} || delim_len=0 # include the delimiter length in the threshhold - local threshhold=$(( $2 + ${#3} )) + local threshhold=$(( $2 + $delim_len )) # loop through the paths for (( i=1; i<${#paths}; i++ )); do # get the current directory value @@ -261,7 +262,7 @@ function truncatePath() { ;; middle) # we need double the length for start and end truncation + delimiter length - local threshhold=$(( $2 * 2 + ${#3} )) + local threshhold=$(( $2 * 2 )) # create a variable for the start of the end truncation local last_pos # loop through the paths @@ -271,7 +272,7 @@ function truncatePath() { test_dir_length=${#test_dir} # only truncate if the resulting truncation will be shorter than # the truncation + delimiter length - if (( $test_dir_length > $threshhold + ${#3} )); then + if (( $test_dir_length > $threshhold )); then # use the first $2 characters, the delimiter and the last $2 characters last_pos=$(( $test_dir_length - $2 )) trunc_path+="${test_dir:0:$2}$3${test_dir:$last_pos:$test_dir_length}/" From ec0f7bdacbd2be5214588ca7c0b63f8b2697e2fd Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:22:04 +0400 Subject: [PATCH 47/64] Update for Travis While zsh accepts the following code: ``` local paths=(${(s:/:)${1//"~\/"/}}) ``` Travis fails unless it is ``` local paths=$1 paths=(${(s:/:)${paths//"~\/"/}}) ``` --- functions/utilities.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 7dee844c..1b2035ac 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -234,7 +234,8 @@ function truncatePath() { # if the path is in the home folder, add "~/" to the start otherwise "/" [[ $1 == "~"* ]] && trunc_path='~/' || trunc_path='/' # split the path into an array using "/" as the delimiter - local paths=(${(s:/:)${1//"~\/"/}}) + local paths=$1 + paths=(${(s:/:)${paths//"~\/"/}}) # declare locals for the directory being tested and its length local test_dir test_dir_length delim_len # do the needed truncation From 2bd3e0f67ee8c4f78cbcf20b6c5c391650ebf5c8 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:33:43 +0400 Subject: [PATCH 48/64] Fixed silly coding error Did `local 3=...` instead of `3=...` --- functions/utilities.zsh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 1b2035ac..b4173b99 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -226,7 +226,7 @@ function truncatePath() { # convert $2 from string to integer 2=$(( $2 )) # set $3 to "" if not defined - [[ -z $3 ]] && local 3="" || 3=$(echo -n $3) + [[ -z $3 ]] && 3="" || 3=$(echo -n $3) # set $4 to "right" if not defined [[ -z $4 ]] && 4="right" # create a variable for the truncated path. @@ -237,14 +237,12 @@ function truncatePath() { local paths=$1 paths=(${(s:/:)${paths//"~\/"/}}) # declare locals for the directory being tested and its length - local test_dir test_dir_length delim_len + local test_dir test_dir_length # do the needed truncation case $4 in right) - # check the length of the delimiter - [[ -z $3 ]] && delim_len=${#3} || delim_len=0 # include the delimiter length in the threshhold - local threshhold=$(( $2 + $delim_len )) + local threshhold=$(( $2 + ${#3} )) # loop through the paths for (( i=1; i<${#paths}; i++ )); do # get the current directory value From 90d0fb1c3209b7f83d49b3a5a7a9168a4778491a Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:42:01 +0400 Subject: [PATCH 49/64] Updated test for trunc_to_unique Instead of testing for number of folders, now only tests if string is longer than 1 character. --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5357dab6..e7cd4acf 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -725,7 +725,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" local paths directory test_dir test_dir_length trunc_path threshhold - (( ${#current_path} > 1 )) && num_paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() # only split if not root/home folder + (( ${#current_path} > 1 )) && num_paths=(${(s:/:)${current_path//"~\/"/}}) || num_paths=() # only split if not root/home folder if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character @@ -818,7 +818,7 @@ prompt_dir() { truncate_to_unique) # for each parent path component find the shortest unique beginning # characters sequence. Source: https://stackoverflow.com/a/45336078 - if (( ${#num_paths} > 0 )); then # root is an exception and won't have paths + 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='' @@ -860,9 +860,9 @@ prompt_dir() { local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ $current_dir == '~' ]]; then + elif [[ $current_path == '~' ]]; then current_state="HOME" - elif [[ $current_dir == '~'* ]]; then + elif [[ $current_path == '~'* ]]; then current_state="HOME_SUBFOLDER" fi From 9c02c6e4d8c7400c4a68a672548e8597a5d6c99f Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:46:53 +0400 Subject: [PATCH 50/64] All code should now be functional *Fingers crossed* --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e7cd4acf..dfa6e4e8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -725,7 +725,7 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { local current_path="$(print -P '%~')" local paths directory test_dir test_dir_length trunc_path threshhold - (( ${#current_path} > 1 )) && num_paths=(${(s:/:)${current_path//"~\/"/}}) || num_paths=() # only split if not root/home folder + (( ${#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 set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character From 9ef8a2f1f9fac91678edec8fd74bcf73bda30a4a Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 22:51:28 +0400 Subject: [PATCH 51/64] Missed one variable name change There's always that one pesky variable name you forget to change... --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dfa6e4e8..e65a82e0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -738,7 +738,7 @@ prompt_dir() { current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) ;; truncate_with_folder_marker) - if (( ${#num_paths} > 0 )); then # root is an exception and won't have paths + if (( ${#paths} > 0 )); then # root is an exception and won't have paths local last_marked_folder marked_folder set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" From 441fb277d92a6e2310a71caa3920be1276a39afe Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 22 Feb 2018 23:34:25 +0400 Subject: [PATCH 52/64] 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(-) 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 From 1e29203563716297c261a3d03406ac0446f55058 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 00:36:12 +0400 Subject: [PATCH 53/64] Removed final SEDs and more comments --- powerlevel9k.zsh-theme | 47 +++++++++++++++++++++++++++++------------- test/powerlevel9k.spec | 14 ++++++------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ebf13e66..2e713bdc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -865,10 +865,6 @@ prompt_dir() { # 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]}" - fi - typeset -AH dir_states dir_states=( "DEFAULT" "FOLDER_ICON" @@ -887,30 +883,43 @@ prompt_dir() { # 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_on="%B"; bld_off="%b" || bld_on=""; bld_off="" - + # test if user wants the last directory printed in bold + if [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]]; then + bld_on="%B" + bld_off="%b" + else + bld_on="" + bld_off="" + fi + # determine is the user has set a last directory color local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND local dir_state_foreground=${(P)dir_state_user_foreground} [[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}" local dir_name base_name + # use ZSH substitution to get the dirname and basename instead of calling external functions dir_name=${path_opt%/*} base_name=${path_opt##*/} + # if the user wants the last directory colored... if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then - if [[ $path_opt == "/" || $path_opt == "~" || "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}${bld_off}" - else + else # has a subfolder + # test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute 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 + else # no coloring + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then current_path="${bld_on}${current_path}${bld_off}" - else + else # has a subfolder + # test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute if [[ $dir_name != $base_name ]]; then current_path="${dir_name}/${bld_on}${base_name}${bld_off}" else @@ -919,16 +928,26 @@ prompt_dir() { fi fi + # check if we need to omit the first character and only do it if we are not in "~" or "/" + if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" && $path_opt != "/" && $path_opt != "~" ]]; then + current_path="${current_path[2,-1]}" + fi + + # check if the user wants the separator colored. if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} && $path_opt != "/" ]]; then - current_path="$( echo "${current_path}" | sed "s/\//%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}\/%F{$dir_state_foreground}/g")" + # because this contains color changing codes, it is easier to set a variable for what should be replaced + local repl="%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}/%F{$dir_state_foreground}" + # escape the / with a \ + current_path=${current_path//\//$repl} fi if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then - current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" + current_path=${current_path//\//$POWERLEVEL9K_DIR_PATH_SEPARATOR} fi if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="$( echo "${current_path}" | sed "s/~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/1")" + # use :s to only replace the first occurance + current_path=${current_path:s/~/$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION} fi "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 5d8c5a31..5f6b6f27 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}%F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %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}%F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %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} %F{black}/tmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black} %F{black}/tmp %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%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{black}/tmp %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%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{green%}icon-here%f %F{black}/tmp %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%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{green%}icon-here%f %F{red}/tmp %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%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}icon-here%f %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON From 5fb3033d58ec4c87162b3e97a0116624bf87a424 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 00:41:36 +0400 Subject: [PATCH 54/64] Update to truncate_absolute --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2e713bdc..10e9852d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -752,7 +752,7 @@ prompt_dir() { 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)} + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} fi ;; truncate_with_folder_marker) From 1abb519f593e42e92ebc7714723bced6d746f934 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 00:45:00 +0400 Subject: [PATCH 55/64] Updated dir.spec tests --- 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 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 From 01f7261df4fdabbe815055c5a42853dc48f07da0 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 08:28:57 +0400 Subject: [PATCH 56/64] Updated README dir truncation strategies Added `truncate_to_last` Added `truncate_absolute` Moved `truncate_to_unique` before folder marker --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f9ee9ca..6642b93f 100644 --- a/README.md +++ b/README.md @@ -377,9 +377,11 @@ 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_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).| -|`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.| For example, if you wanted the truncation behavior of the `fish` shell, which truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: From 08432bf70c1874ab4f67538f85e7be50847f1c5d Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:28:56 +0400 Subject: [PATCH 57/64] 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(-) 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" From 3674af1cd9788b144a39358913f95979762dbb00 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:37:49 +0400 Subject: [PATCH 58/64] Updated dir.spec test for first_and_last --- 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 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 From 99e62532bb1cab11df5f86d021014930a94bed0d Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:53:36 +0400 Subject: [PATCH 59/64] Added test for root based folder to first&last --- powerlevel9k.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 17909c61..051ffb8f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -766,7 +766,8 @@ prompt_dir() { for (( i=$POWERLEVEL9K_SHORTEN_DIR_LENGTH; i<$num; i++ )); do paths[$i+1]=$POWERLEVEL9K_SHORTEN_DELIMITER done - current_path="${(j:/:)paths}" + [[ $current_path ~= '~'* ]] && current_path="/" || current_path="" + current_path+="${(j:/:)paths}" fi fi ;; From b723800b801f8bfc1aa997eea1f03d4279f96f3e Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 09:56:42 +0400 Subject: [PATCH 60/64] Fixed typo - ~= instead of != --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 051ffb8f..d60219eb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -766,7 +766,7 @@ prompt_dir() { for (( i=$POWERLEVEL9K_SHORTEN_DIR_LENGTH; i<$num; i++ )); do paths[$i+1]=$POWERLEVEL9K_SHORTEN_DELIMITER done - [[ $current_path ~= '~'* ]] && current_path="/" || current_path="" + [[ $current_path != '~'* ]] && current_path="/" || current_path="" current_path+="${(j:/:)paths}" fi fi From ddcdad77a73d971a77283d90fd3ba78e0f61dc66 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:08:43 +0400 Subject: [PATCH 61/64] 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(-) 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' From 75a763f9018595ad861966e11de560ab00b8cd87 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:12:56 +0400 Subject: [PATCH 62/64] Updated test for POWERLEVEL9K_DIR_PATH_ABSOLUTE --- test/segments/dir.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5cec4d652a7428bfc8900f84be0bb6885e2e12ef Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:21:02 +0400 Subject: [PATCH 63/64] Added POWERLEVEL9K_DIR_PATH_ABSOLUTE to README.md --- README.md | 1 + powerlevel9k.zsh-theme | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1dbe756e..26298b18 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,7 @@ Customizations available are: | Variable | Default Value | Description | |----------|---------------|-------------| +|`POWERLEVEL9K_DIR_PATH_ABSOLUTE`|None|If set to `true`, will use absolute paths instead of home folder abbreviation `~`| |`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is entire directories, this field determines how many directories to leave at the end. If your shorten strategy is by character count, this field determines how many characters to allow per directory string.| |`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. See the table below for more informations.| |`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c404c0c2..baf46336 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -894,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 == $HOME ]]; then # changed '~' to $HOME for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE + elif [[ "$state_path" == "$HOME" ]]; then # changed '~' to $HOME for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE current_state="HOME" - elif [[ $state_path == $HOME* ]]; then # changed '~'* to $HOME* for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE + elif [[ "$state_path" == "$HOME"* ]]; then # changed '~'* to $HOME* for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE current_state="HOME_SUBFOLDER" fi From 9b7f8babe7f7eb4cd4330c1ba4534150baa90b82 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 23 Feb 2018 10:25:56 +0400 Subject: [PATCH 64/64] Updated testing for folder icons --- powerlevel9k.zsh-theme | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index baf46336..8dd2d957 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -727,8 +727,6 @@ prompt_dir() { 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 local paths directory test_dir test_dir_length trunc_path threshhold # if we are not in "~" or "/", split the paths into an array and exclude "~" @@ -891,12 +889,13 @@ prompt_dir() { "HOME_SUBFOLDER" "HOME_SUB_ICON" "NOT_WRITABLE" "LOCK_ICON" ) + local state_path="$(print -P '%~')" local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ "$state_path" == "$HOME" ]]; then # changed '~' to $HOME for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE + elif [[ $state_path == '~' ]]; then current_state="HOME" - elif [[ "$state_path" == "$HOME"* ]]; then # changed '~'* to $HOME* for compatibility with POWERLEVEL9K_DIR_PATH_ABSOLUTE + elif [[ $state_path == '~'* ]]; then current_state="HOME_SUBFOLDER" fi