From 1ba90abd4afc97a9a7916f7a85651008d53d9c81 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sun, 19 May 2019 15:53:09 +0200 Subject: [PATCH] truncate_to_unique: respect POWERLEVEL9K_SHORTEN_FOLDER_MARKER with default value of (.bzr|CVS|.git|.hg|.svn|.citc) --- powerlevel9k.zsh-theme | 48 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 33e70df1..bf4c71a8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -792,9 +792,6 @@ set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false set_default POWERLEVEL9K_SHORTEN_STRATEGY "" 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 # 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 @@ -895,33 +892,46 @@ prompt_dir() { fi ;; truncate_to_unique) - local parent="${PWD%/${(pj./.)parts[2,-1]}}" dir='' - local -i i=2 - for (( ; i < $#parts; ++i )); do + local -i i=2 n=1 + [[ $p == /* ]] && (( ++i )) + (( 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] + if [[ -n $pat ]]; then + local -a matches=($parent/$dir/${~pat}(N)) + if (( $#matches )); then + parent+=/$dir + continue + fi + fi local -i j=1 for (( ; j < $#dir; ++j )); do local -a matching=($parent/$dir[1,j]*/(N)) (( $#matching == 1 )) && break done - parent+=/$dir (( j == $#dir )) || parts[i]=$dir[1,j]$'\0' + parent+=/$dir done delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'} ;; truncate_with_folder_marker) - local dir=$PWD - local -a m=() - local -i i=$(($#parts - 1)) - for (( ; i > 1; --i )); do - dir=${dir:h} - local -a matches=($dir/${~POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(N)) - (( $#matches )) && m+=$i - done - m+=1 - for (( i=1; i < $#m; ++i )); do - (( m[i] - m[i+1] > 2 )) && parts[m[i+1]+1,m[i]-1]=($'\0') - done + local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-.shorten_folder_marker} + if [[ -n $pat ]]; then + local dir=$PWD + local -a m=() + local -i i=$(($#parts - 1)) + for (( ; i > 1; --i )); do + dir=${dir:h} + local -a matches=($dir/${~pat}(N)) + (( $#matches )) && m+=$i + done + m+=1 + 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