← Back to context

Comment by kleiba

6 hours ago

Just recently, I came up with this in my .bashrc, basically a "deep cd" command:

    dcd() {
        # If no argument is given, do nothing
        [ -z "$1" ] && return

        # Find the first matching directory under the current directory
        local dir
        dir=$(find . -type d -path "*$1*" -print -quit 2>/dev/null)

        # If a directory was found, cd into it
        [ -n "$dir" ] && cd "$dir"
    }

I thought this would be way too slow for actual use, but I've come to love it.

you should look into autojump which has `jc` (jump child), or other similar flavours of "smart cd" (z, fzf, etc)

  • Thanks, but I like that this is just a small, simple bash function without the need to install 3rd-party software.