cd : make cdd find first match.
This commit is contained in:
parent
33386c9206
commit
b184ca5cc1
|
@ -12,17 +12,26 @@ cdd()
|
|||
shopt -s nocasematch
|
||||
|
||||
# Find desired dir.
|
||||
for dir in "${array[@]}"; do
|
||||
result="${result}/${dir}"
|
||||
[[ "${dir}" =~ "${target}" ]] && break
|
||||
# for dir in "${array[@]}"; do
|
||||
# result="${result}/${dir}"
|
||||
# [[ "${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
|
||||
|
||||
# Clean-up???
|
||||
shopt -u nocasematch
|
||||
|
||||
# Say where we're going.
|
||||
echo "${result}"
|
||||
|
||||
# Go there!
|
||||
cd "${result}"
|
||||
if [[ "${result}" != "" ]]; then
|
||||
echo "${result}"
|
||||
cd "${result}"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
Reference in a new issue