cd : make cdd find first match.
This commit is contained in:
parent
33386c9206
commit
b184ca5cc1
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue