add truncate_to_unique specific SHORTEN_DIR_LENGTH default

pull/73/head
Syphdias 6 years ago
parent c581623801
commit bead0ec05e
No known key found for this signature in database
GPG Key ID: 6F62E6FB3E67F92D

@ -735,7 +735,6 @@ set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false
set_default POWERLEVEL9K_SHORTEN_STRATEGY "" set_default POWERLEVEL9K_SHORTEN_STRATEGY ""
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND "" set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ""
set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1
# Individual elements are patterns. They are expanded with the options set by `emulate zsh`. # Individual elements are patterns. They are expanded with the options set by `emulate zsh`.
set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json
@ -768,13 +767,14 @@ prompt_dir() {
local -a parts=("${(s:/:)p}") local -a parts=("${(s:/:)p}")
fi fi
local -i fake_first=0 local -i fake_first=0 shortenlen
local delim=${POWERLEVEL9K_SHORTEN_DELIMITER-$'\u2026'} local delim=${POWERLEVEL9K_SHORTEN_DELIMITER-$'\u2026'}
local shortenlen=${POWERLEVEL9K_SHORTEN_DIR_LENGTH:--1}
case $POWERLEVEL9K_SHORTEN_STRATEGY in case $POWERLEVEL9K_SHORTEN_STRATEGY in
truncate_absolute|truncate_absolute_chars) truncate_absolute|truncate_absolute_chars)
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 && $#p > POWERLEVEL9K_SHORTEN_DIR_LENGTH + 1 )); then if (( shortenlen > 0 && $#p > shortenlen + 1 )); then
local -i n=POWERLEVEL9K_SHORTEN_DIR_LENGTH local -i n=shortenlen
local -i i=$#parts local -i i=$#parts
while true; do while true; do
local dir=$parts[i] local dir=$parts[i]
@ -809,8 +809,8 @@ prompt_dir() {
dir=${dir:h} dir=${dir:h}
done done
} }
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then if (( shortenlen > 0 )); then
local -i pref=$POWERLEVEL9K_SHORTEN_DIR_LENGTH suf=0 i=2 local -i pref=$shortenlen suf=0 i=2
[[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_middle ]] && suf=pref [[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_middle ]] && suf=pref
for (( ; i < $#parts; ++i )); do for (( ; i < $#parts; ++i )); do
local dir=$parts[i] local dir=$parts[i]
@ -826,10 +826,10 @@ prompt_dir() {
parts[1,-2]=() parts[1,-2]=()
;; ;;
truncate_to_first_and_last) truncate_to_first_and_last)
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then if (( shortenlen > 0 )); then
local -i i=$(( POWERLEVEL9K_SHORTEN_DIR_LENGTH + 1 )) local -i i=$(( shortenlen + 1 ))
[[ $p == /* ]] && (( ++i )) [[ $p == /* ]] && (( ++i ))
for (( ; i <= $#parts - POWERLEVEL9K_SHORTEN_DIR_LENGTH; ++i )); do for (( ; i <= $#parts - shortenlen; ++i )); do
parts[i]=$'\0' parts[i]=$'\0'
done done
fi fi
@ -837,8 +837,9 @@ prompt_dir() {
truncate_to_unique) truncate_to_unique)
local -i i=2 n=1 d=0 local -i i=2 n=1 d=0
delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'} delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'}
shortenlen=${POWERLEVEL9K_SHORTEN_DIR_LENGTH:-1}
d=${POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:-$#POWERLEVEL9K_SHORTEN_DELIMITER} d=${POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:-$#POWERLEVEL9K_SHORTEN_DELIMITER}
(( POWERLEVEL9K_SHORTEN_DIR_LENGTH >= 0 )) && n=POWERLEVEL9K_SHORTEN_DIR_LENGTH (( shortenlen >= 0 )) && n=shortenlen
local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-'(.bzr|CVS|.git|.hg|.svn|.citc)'} local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-'(.bzr|CVS|.git|.hg|.svn|.citc)'}
local parent="${PWD%/${(pj./.)parts[i,-1]}}" local parent="${PWD%/${(pj./.)parts[i,-1]}}"
for (( ; i <= $#parts - n; ++i )); do for (( ; i <= $#parts - n; ++i )); do
@ -877,11 +878,11 @@ prompt_dir() {
fi fi
;; ;;
*) *)
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then if (( shortenlen > 0 )); then
local -i len=$#parts local -i len=$#parts
[[ -z $parts[1] ]] && (( --len )) [[ -z $parts[1] ]] && (( --len ))
if (( len > POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then if (( len > shortenlen )); then
parts[1,-POWERLEVEL9K_SHORTEN_DIR_LENGTH-1]=($'\0') parts[1,-shortenlen-1]=($'\0')
fi fi
fi fi
;; ;;

Loading…
Cancel
Save