29 lines
483 B
Bash
29 lines
483 B
Bash
# CD (back) to directory.
|
|
# Usage: cdd <DIR>
|
|
cdd()
|
|
{
|
|
local target="${1}"
|
|
local array
|
|
local result
|
|
IFS='/' read -r -a array <<< "${PWD}"
|
|
array=("${array[@]:1}")
|
|
|
|
# Make search case-insensitive.
|
|
shopt -s nocasematch
|
|
|
|
# Find desired dir.
|
|
for dir in "${array[@]}"; do
|
|
result="${result}/${dir}"
|
|
[[ "${dir}" =~ "${target}" ]] && break
|
|
done
|
|
|
|
# Clean-up???
|
|
shopt -u nocasematch
|
|
|
|
# Say where we're going.
|
|
echo "${result}"
|
|
|
|
# Go there!
|
|
cd "${result}"
|
|
}
|