Merge pull request #915 from onaforeignshore/fix_truncate_to_unique

[Bugfix] Fix for "truncate_to_unique" strategy
pull/22/head
Ben Hilburn 6 years ago committed by GitHub
commit e70ce43809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save