support autocd option (#695)

* support autocd option

In bash, when autocd option is set and user enters a directory name as a
command, it results in a very specific call to cd:

cd -- [directory name]

zoxide's directory changing function passes all arguments to __zoxide_z as is,
including the "--" first argument. By detecting this and skipping the first
argument changing directory works with autocd set.

* remove directory check

just skip the first argument and pass the rest as is. checking for directory
breaks cd'ing to symlinked directories

* undo some of the hackery

tests are failing
This commit is contained in:
solodov 2024-06-25 13:17:33 -04:00 committed by GitHub
parent b881866216
commit 8da8f50eaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -75,6 +75,8 @@ function __zoxide_z() {
__zoxide_cd "${OLDPWD}" __zoxide_cd "${OLDPWD}"
elif [[ $# -eq 1 && -d $1 ]]; then elif [[ $# -eq 1 && -d $1 ]]; then
__zoxide_cd "$1" __zoxide_cd "$1"
elif [[ $# -eq 2 && $1 == '--' ]]; then
__zoxide_cd "$2"
elif [[ ${@: -1} == "${__zoxide_z_prefix}"?* ]]; then elif [[ ${@: -1} == "${__zoxide_z_prefix}"?* ]]; then
# shellcheck disable=SC2124 # shellcheck disable=SC2124
\builtin local result="${@: -1}" \builtin local result="${@: -1}"