summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-23 09:08:43 +0300
committerChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-23 09:08:43 +0300
commitddcdad77a73d971a77283d90fd3ba78e0f61dc66 (patch)
tree4d4501c3fdb30d9d466c62db36f8de6eefcb2cca
parentb723800b801f8bfc1aa997eea1f03d4279f96f3e (diff)
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 ~/...
-rwxr-xr-xpowerlevel9k.zsh-theme9
-rwxr-xr-xtest/segments/dir.spec10
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'