cdd : go to previous directory that matches.
This commit is contained in:
parent
ba1d41d18c
commit
87c6ed7fdd
|
@ -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
28
.config/bash/module/cd.sh
Normal 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}"
|
||||
}
|
Reference in a new issue