cd : make cdd find first match.

This commit is contained in:
Dmitry Voronin 2023-11-26 02:31:08 +03:00
parent 33386c9206
commit b184ca5cc1

View file

@ -12,17 +12,26 @@ cdd()
shopt -s nocasematch shopt -s nocasematch
# Find desired dir. # Find desired dir.
for dir in "${array[@]}"; do # for dir in "${array[@]}"; do
result="${result}/${dir}" # result="${result}/${dir}"
[[ "${dir}" =~ "${target}" ]] && break # [[ "${dir}" =~ "${target}" ]] && break
# done
local found=1
for (( idx=${#array[@]}-2 ; idx>=0 ; idx-- )); do
dir="${array[idx]}"
[[ "${dir}" =~ "${target}" ]] && found=0
[[ ${found} = 0 ]] && result="/${dir}${result}"
done done
# Clean-up??? # Clean-up???
shopt -u nocasematch shopt -u nocasematch
# Say where we're going.
echo "${result}"
# Go there! # Go there!
cd "${result}" if [[ "${result}" != "" ]]; then
echo "${result}"
cd "${result}"
else
return 1
fi
} }