mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-21 06:41:57 +00:00
support multiple markers with POWERLEVEL9K_SHORTEN_STRATEGY=truncate_with_folder_marker
This commit is contained in:
parent
b910da06a0
commit
bd4a3503d2
1 changed files with 21 additions and 19 deletions
|
@ -784,11 +784,6 @@ prompt_command_execution_time() {
|
||||||
"$1_prompt_segment" "$0" "$2" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' "${humanReadableDuration}"
|
"$1_prompt_segment" "$0" "$2" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' "${humanReadableDuration}"
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################
|
|
||||||
# Dir: current working directory
|
|
||||||
# Parameters:
|
|
||||||
# * $1 Alignment: string - left|right
|
|
||||||
# * $2 Index: integer
|
|
||||||
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
|
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
|
||||||
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
|
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
|
||||||
set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false
|
set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false
|
||||||
|
@ -798,9 +793,15 @@ 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 POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026'
|
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026'
|
||||||
|
# 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 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`.
|
||||||
set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json
|
set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Dir: current working directory
|
||||||
prompt_dir() {
|
prompt_dir() {
|
||||||
[[ $POWERLEVEL9K_DIR_PATH_ABSOLUTE == true ]] && local p=$PWD || local p=${(%):-%~}
|
[[ $POWERLEVEL9K_DIR_PATH_ABSOLUTE == true ]] && local p=$PWD || local p=${(%):-%~}
|
||||||
|
|
||||||
|
@ -851,21 +852,21 @@ prompt_dir() {
|
||||||
;;
|
;;
|
||||||
truncate_with_package_name|truncate_middle|truncate_from_right)
|
truncate_with_package_name|truncate_middle|truncate_from_right)
|
||||||
() {
|
() {
|
||||||
[[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name ]] || return
|
[[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name &&
|
||||||
|
$+commands[jq] == 1 && $#POWERLEVEL9K_DIR_PACKAGE_FILES > 0 ]] || return
|
||||||
|
local pat="(${(j:|:)POWERLEVEL9K_DIR_PACKAGE_FILES})"
|
||||||
local -i i=$#parts
|
local -i i=$#parts
|
||||||
local pkg_dir=$PWD
|
local dir=$PWD
|
||||||
for (( ; i > 0; --i )); do
|
for (( ; i > 0; --i )); do
|
||||||
local fname=''
|
local pkg_file=''
|
||||||
for fname in $POWERLEVEL9K_DIR_PACKAGE_FILES; do
|
for pkg_file in $dir/${~pat}(N); do
|
||||||
if [[ -f $pkg_dir/$fname ]]; then
|
local pkg_name=''
|
||||||
local pkg_name=''
|
pkg_name=$(command jq -j '.name' <$pkg_file) && [[ -n $pkg_name ]] || return
|
||||||
pkg_name=$(jq -j '.name' <$pkg_dir/$fname) && [[ -n $pkg_name ]] || return
|
parts[1,i]=($pkg_name)
|
||||||
parts[1,i]=($pkg_name)
|
fake_first=1
|
||||||
fake_first=1
|
return
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
pkg_dir=${pkg_dir:h}
|
dir=${dir:h}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then
|
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then
|
||||||
|
@ -900,7 +901,7 @@ prompt_dir() {
|
||||||
local dir=$parts[i]
|
local dir=$parts[i]
|
||||||
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]*/)
|
local -a matching=($parent/$dir[1,j]*/(N))
|
||||||
(( $#matching == 1 )) && break
|
(( $#matching == 1 )) && break
|
||||||
done
|
done
|
||||||
parent+=/$dir
|
parent+=/$dir
|
||||||
|
@ -913,7 +914,8 @@ prompt_dir() {
|
||||||
local -i i=$(($#parts - 1))
|
local -i i=$(($#parts - 1))
|
||||||
for (( ; i > 1; --i )); do
|
for (( ; i > 1; --i )); do
|
||||||
dir=${dir:h}
|
dir=${dir:h}
|
||||||
[[ -e $dir/$POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]] && m+=$i
|
local -a matches=($dir/${~POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(N))
|
||||||
|
(( $#matches )) && m+=$i
|
||||||
done
|
done
|
||||||
m+=1
|
m+=1
|
||||||
for (( i=1; i < $#m; ++i )); do
|
for (( i=1; i < $#m; ++i )); do
|
||||||
|
|
Loading…
Reference in a new issue