mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-16 17:50:09 +00:00
Merge pull request #915 from onaforeignshore/fix_truncate_to_unique
[Bugfix] Fix for "truncate_to_unique" strategy
This commit is contained in:
commit
e70ce43809
1 changed files with 29 additions and 17 deletions
|
@ -744,6 +744,31 @@ prompt_command_execution_time() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Determine the unique path - this is needed for the
|
||||||
|
# truncate_to_unique strategy.
|
||||||
|
#
|
||||||
|
function getUniqueFolder() {
|
||||||
|
local trunc_path directory test_dir test_dir_length
|
||||||
|
local -a matching
|
||||||
|
local -a paths
|
||||||
|
local cur_path='/'
|
||||||
|
paths=(${(s:/:)1})
|
||||||
|
for directory in ${paths[@]}; do
|
||||||
|
test_dir=''
|
||||||
|
for (( i=0; i < ${#directory}; i++ )); do
|
||||||
|
test_dir+="${directory:$i:1}"
|
||||||
|
matching=("$cur_path"/"$test_dir"*/)
|
||||||
|
if [[ ${#matching[@]} -eq 1 ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
trunc_path+="$test_dir/"
|
||||||
|
cur_path+="$directory/"
|
||||||
|
done
|
||||||
|
echo "${trunc_path: : -1}"
|
||||||
|
}
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Dir: current working directory
|
# Dir: current working directory
|
||||||
# Parameters:
|
# Parameters:
|
||||||
|
@ -811,23 +836,10 @@ prompt_dir() {
|
||||||
# for each parent path component find the shortest unique beginning
|
# for each parent path component find the shortest unique beginning
|
||||||
# characters sequence. Source: https://stackoverflow.com/a/45336078
|
# characters sequence. Source: https://stackoverflow.com/a/45336078
|
||||||
if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths
|
if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths
|
||||||
local matching
|
# cheating here to retain ~ as home folder
|
||||||
local cur_path='/'
|
local home_path="$(getUniqueFolder $HOME)"
|
||||||
[[ $current_path != "~"* ]] && trunc_path='/' || trunc_path=''
|
trunc_path="$(getUniqueFolder $PWD)"
|
||||||
for directory in ${paths[@]}; do
|
[[ $current_path == "~"* ]] && current_path="~${trunc_path//${home_path}/}" || current_path="/${trunc_path}"
|
||||||
test_dir=''
|
|
||||||
for (( i=0; i<${#directory}; i++ )); do
|
|
||||||
test_dir+="${directory:$i:1}"
|
|
||||||
matching=("$cur_path"/"$test_dir"*/)
|
|
||||||
if [[ ${#matching[@]} -eq 1 ]]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
trunc_path+="$test_dir/"
|
|
||||||
cur_path+="$directory/"
|
|
||||||
done
|
|
||||||
[[ $current_path == "~"* ]] && trunc_path="~/$trunc_path"
|
|
||||||
current_path="${trunc_path: : -1}"
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
truncate_with_folder_marker)
|
truncate_with_folder_marker)
|
||||||
|
|
Loading…
Reference in a new issue