1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-29 06:40:08 +00:00

truncate_to_unique: respect POWERLEVEL9K_SHORTEN_FOLDER_MARKER with default value of (.bzr|CVS|.git|.hg|.svn|.citc)

This commit is contained in:
romkatv 2019-05-19 15:53:09 +02:00
parent 3c5b52750e
commit 1ba90abd4a

View file

@ -792,9 +792,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 ""
# This defines a pattern. It is expanded with the options set by `emulate zsh`.
# This works pretty well: POWERLEVEL9K_SHORTEN_FOLDER_MARKER="(.bzr|CVS|.git|.hg|.svn|.citc)"
set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker"
set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1 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
@ -895,33 +892,46 @@ prompt_dir() {
fi fi
;; ;;
truncate_to_unique) truncate_to_unique)
local parent="${PWD%/${(pj./.)parts[2,-1]}}" dir='' local -i i=2 n=1
local -i i=2 [[ $p == /* ]] && (( ++i ))
for (( ; i < $#parts; ++i )); do (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )) && n=POWERLEVEL9K_SHORTEN_DIR_LENGTH
local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-'(.bzr|CVS|.git|.hg|.svn|.citc)'}
local parent="${PWD%/${(pj./.)parts[i,-1]}}"
for (( ; i <= $#parts - n; ++i )); do
local dir=$parts[i] local dir=$parts[i]
if [[ -n $pat ]]; then
local -a matches=($parent/$dir/${~pat}(N))
if (( $#matches )); then
parent+=/$dir
continue
fi
fi
local -i j=1 local -i j=1
for (( ; j < $#dir; ++j )); do for (( ; j < $#dir; ++j )); do
local -a matching=($parent/$dir[1,j]*/(N)) local -a matching=($parent/$dir[1,j]*/(N))
(( $#matching == 1 )) && break (( $#matching == 1 )) && break
done done
parent+=/$dir
(( j == $#dir )) || parts[i]=$dir[1,j]$'\0' (( j == $#dir )) || parts[i]=$dir[1,j]$'\0'
parent+=/$dir
done done
delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'} delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'}
;; ;;
truncate_with_folder_marker) truncate_with_folder_marker)
local dir=$PWD local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-.shorten_folder_marker}
local -a m=() if [[ -n $pat ]]; then
local -i i=$(($#parts - 1)) local dir=$PWD
for (( ; i > 1; --i )); do local -a m=()
dir=${dir:h} local -i i=$(($#parts - 1))
local -a matches=($dir/${~POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(N)) for (( ; i > 1; --i )); do
(( $#matches )) && m+=$i dir=${dir:h}
done local -a matches=($dir/${~pat}(N))
m+=1 (( $#matches )) && m+=$i
for (( i=1; i < $#m; ++i )); do done
(( m[i] - m[i+1] > 2 )) && parts[m[i+1]+1,m[i]-1]=($'\0') m+=1
done for (( i=1; i < $#m; ++i )); do
(( m[i] - m[i+1] > 2 )) && parts[m[i+1]+1,m[i]-1]=($'\0')
done
fi
;; ;;
*) *)
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then