1

I'm using zsh & I've aliased .. to cd ... I want zsh to cd to a path if and only if the typed out path is a repetition of .. or ../.

The following should auto-cd:

..
../
../../../../
../../..

These should not auto-cd:

../../mydir
mydir
/dir

How can I configure zsh (and maybe bash) to auto-cd like so?

1 Answer 1

0

You can use the 'DEBUG' trap to intercept commands, e.g. to emulate 'autocd':

TRAPDEBUG() {
    if [[ "$ZSH_DEBUG_CMD" =~ ^\\.\\.(/\\.\\.)*/?$ ]]; then
        : "Emulate autocd"
        cd "$ZSH_DEBUG_CMD"
        echo "Now in $PWD"
        : "Cancel the original command"
        set -e
    fi
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .