From 8f603093862d519caad072e102d22c515e8847b5 Mon Sep 17 00:00:00 2001 From: Wuestengecko <1579756+Wuestengecko@users.noreply.github.com> Date: Fri, 1 Feb 2019 17:43:52 +0100 Subject: [PATCH 1/2] Only abbreviate $HOME at the beginning of cwd Fixes #1150 --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 63724823..43d423a0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -797,7 +797,7 @@ prompt_dir() { # 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/"~"} + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path/#$HOME/"~"} # 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 "~" From 8bb86908d74097cda237115273acfdbaa5f39ea1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 23:48:39 +0100 Subject: [PATCH 2/2] Add tests --- test/segments/dir.spec | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 46e0cfb8..d75ca42f 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -768,4 +768,22 @@ function testDirSeparatorColorRootSubSubdirWorks() { rm -fr /tmp/powerlevel9k-test } +function testDirHomeTruncationWorksOnlyAtTheBeginning() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + + local FOLDER=/tmp/p9ktest + local SAVED_HOME="${HOME}" + HOME="/p9ktest" + + mkdir -p $FOLDER + # Setup folder marker + cd $FOLDER + assertEquals "%K{004} %F{000}/tmp/p9ktest %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $FOLDER + HOME="${SAVED_HOME}" +} + source shunit2/shunit2