diff --git a/.config/bash/module/cd.sh b/.config/bash/module/cd.sh index 0a3d484..7d242dc 100644 --- a/.config/bash/module/cd.sh +++ b/.config/bash/module/cd.sh @@ -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 }