From 2bc3b09963f34e3f404556100f28b4bf4e904a92 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 25 Jul 2015 01:34:11 +0200 Subject: [PATCH 1/2] Implemented different ways to truncate the directory path. --- README.md | 12 ++++++++++++ powerlevel9k.zsh-theme | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71dfceb2..4aec6745 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,18 @@ to a certain length: # Limit to the last two folders POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 +To change the way how the current working directory is truncated, just set: + + # truncate whole directories + POWERLEVEL9K_SHORTEN_STRATEGY="complete_directories" + # truncate from right, leaving the first X characters untouched + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" + # default behaviour is to truncate the middle part of the directory + +In each case you have to specify the length you want to shorten the directory +to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in +others whole directories. + #### The 'time' segment By default the time is show in 'H:M:S' format. If you want to change it, diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 69eee6e3..3e793d7e 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -450,8 +450,19 @@ prompt_context() { prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then - # shorten path to $POWERLEVEL9K_SHORTEN_DIR_LENGTH - current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + + case "$POWERLEVEL9K_SHORTEN_STRATEGY" in + complete_directories) + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + ;; + truncate_from_right) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + ;; + *) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") + ;; + esac + fi $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path" From 99504d4ad44ea88af8ec6f84c8c38415044e7557 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 29 Jul 2015 23:46:06 +0200 Subject: [PATCH 2/2] Add an indicator that directories were truncated. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3e793d7e..da3e617b 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -456,7 +456,7 @@ prompt_dir() { current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; truncate_from_right) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") ;; *) current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g")