From d0a6843d2bc4051fe3e46bcaf211814936c68534 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Sat, 4 Jul 2026 15:51:04 +0530 Subject: [PATCH] Bash/POSIX: check directory existence using cd --- CHANGELOG.md | 4 +++- templates/bash.txt | 2 +- templates/posix.txt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a33d039..d45d2d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `import` now skips directories matching `$_ZO_EXCLUDE_DIRS`. - POSIX: support for non-Cygwin Windows environments (e.g. Busybox). - Fish: Space-Tab completions now display and run the selected command. +- Bash/POSIX: `z` now honors `$CDPATH`. ### Changed @@ -24,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Bash/Fish/POSIX/Zsh: resolve symlinks on Windows. +- Bash/POSIX: `z` now handles relative paths through symlinked directories. +- Bash/Fish/POSIX/Zsh: `_ZO_RESOLVE_SYMLINKS` now works on Windows. - Bash: handle `$PROMPT_COMMAND` values ending in a semicolon. - PowerShell: navigate to home directory with `z` on drives that don't define `HOME`. - PowerShell: use fully qualified names when invoking cmdlets. diff --git a/templates/bash.txt b/templates/bash.txt index e268a9d..2244ed7 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -111,7 +111,7 @@ function __zoxide_z() { __zoxide_cd ~ elif [[ $# -eq 1 && $1 == '-' ]]; then __zoxide_cd "${OLDPWD}" - elif [[ $# -eq 1 && -d $1 ]]; then + elif [[ $# -eq 1 ]] && (\builtin cd -- "$1") &>/dev/null; then __zoxide_cd "$1" elif [[ $# -eq 2 && $1 == '--' ]]; then __zoxide_cd "$2" diff --git a/templates/posix.txt b/templates/posix.txt index 7a1b888..7c48f27 100644 --- a/templates/posix.txt +++ b/templates/posix.txt @@ -105,7 +105,7 @@ __zoxide_z() { \command printf 'zoxide: $OLDPWD is not set' return 1 fi - elif [ "$#" -eq 1 ] && [ -d "$1" ]; then + elif [ "$#" -eq 1 ] && (\command cd -- "$1") >/dev/null 2>&1; then __zoxide_cd "$1" else __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \command true)" -- "$@")" &&