diff --git a/templates/bash.txt b/templates/bash.txt index 86a2884..254770e 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 && -d ${1%%+(/)} ]]; then __zoxide_cd "$1" elif [[ $# -eq 2 && $1 == '--' ]]; then __zoxide_cd "$2" diff --git a/templates/fish.txt b/templates/fish.txt index a13edc7..d440ece 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -79,7 +79,7 @@ function __zoxide_z __zoxide_cd $HOME else if test "$argv" = - __zoxide_cd - - else if test $argc -eq 1 -a -d $argv[1] + else if test $argc -eq 1 -a -d (string replace -r '/+$' '' -- $argv[1]) __zoxide_cd $argv[1] else if test $argc -eq 2 -a $argv[1] = -- __zoxide_cd -- $argv[2] diff --git a/templates/posix.txt b/templates/posix.txt index b3f660c..282ac44 100644 --- a/templates/posix.txt +++ b/templates/posix.txt @@ -105,8 +105,18 @@ __zoxide_z() { \command printf 'zoxide: $OLDPWD is not set' return 1 fi - elif [ "$#" -eq 1 ] && [ -d "$1" ]; then - __zoxide_cd "$1" + elif [ "$#" -eq 1 ]; then + __zoxide_arg="$1" + # Strip trailing slashes for directory test + while [ "${__zoxide_arg}" != "${__zoxide_arg%/}" ] && [ "${__zoxide_arg}" != / ]; do + __zoxide_arg="${__zoxide_arg%/}" + done + if [ -d "${__zoxide_arg}" ]; then + __zoxide_cd "$1" + else + __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \command true)" -- "$@")" && + __zoxide_cd "${__zoxide_result}" + fi else __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \command true)" -- "$@")" && __zoxide_cd "${__zoxide_result}" diff --git a/templates/tcsh.txt b/templates/tcsh.txt index b0559a0..fd2a1f5 100644 --- a/templates/tcsh.txt +++ b/templates/tcsh.txt @@ -38,8 +38,14 @@ if ("$#__zoxide_args" == 0) then\ else\ if ("$#__zoxide_args" == 1 && "$__zoxide_args[1]" == "-") then\ cd -\ - else if ("$#__zoxide_args" == 1 && -d "$__zoxide_args[1]") then\ - cd "$__zoxide_args[1]"\ + else if ("$#__zoxide_args" == 1) then\ + set __zoxide_arg_tmp = `echo "$__zoxide_args[1]" | sed "s|/*$||"`\ + if (-d "$__zoxide_arg_tmp") then\ + cd "$__zoxide_args[1]"\ + else\ + set __zoxide_pwd = `{{ pwd_cmd }}`\ + set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' -- $__zoxide_args`" && cd "$__zoxide_result"\ + endif\ else\ set __zoxide_pwd = `{{ pwd_cmd }}`\ set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' -- $__zoxide_args`" && cd "$__zoxide_result"\ diff --git a/templates/zsh.txt b/templates/zsh.txt index a66f960..b4120f8 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -88,7 +88,7 @@ function __zoxide_z() { __zoxide_doctor if [[ "$#" -eq 0 ]]; then __zoxide_cd ~ - elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]+$ ]]; }; then + elif [[ "$#" -eq 1 ]] && { [[ -d "${1%%/##}" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]+$ ]]; }; then __zoxide_cd "$1" elif [[ "$#" -eq 2 ]] && [[ "$1" = "--" ]]; then __zoxide_cd "$2"