diff --git a/.README.md b/.README.md index 380273b..aab4d11 100644 --- a/.README.md +++ b/.README.md @@ -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 `|Cd back to previous directory by name. + ## Checksum. Command|Description diff --git a/.config/bash/module/cd.sh b/.config/bash/module/cd.sh new file mode 100644 index 0000000..a48d531 --- /dev/null +++ b/.config/bash/module/cd.sh @@ -0,0 +1,28 @@ +# CD (back) to directory. +# Usage: cdd +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}" +}