cdd : go to previous directory that matches.

This commit is contained in:
Dmitry Voronin 2023-11-25 21:13:55 +03:00
parent ba1d41d18c
commit 87c6ed7fdd
2 changed files with 34 additions and 0 deletions

View file

@ -355,6 +355,12 @@ Command|Description
`bootstrap_grub`|Install grub theme. Requires root.
`bootstrap_ffmpeg`|Install ffmpeg in flatpak to make `~/app/bin/ffmpeg` work.
## Cd.
Command|Description
---|---
`cdd <DIR>`|Cd back to previous directory by name.
## Checksum.
Command|Description

28
.config/bash/module/cd.sh Normal file
View file

@ -0,0 +1,28 @@
# 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 -n nocasematch
# Say where we're going.
echo "${result}"
# Go there!
cd "${result}"
}