From 3c76c63b5b41bd58e2444190d8171c41011ea9a6 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Fri, 18 Dec 2020 07:38:29 +0530 Subject: [PATCH] Invoke cd in subshell --- templates/bash.txt | 2 +- templates/posix.txt | 2 +- templates/zsh.txt | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/bash.txt b/templates/bash.txt index 5aa15ea..50ed2d3 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -75,7 +75,7 @@ function __zoxide_z() { echo 'zoxide: $OLDPWD is not set' return 1 fi - elif [ "$#" -eq 1 ] && [ -d "$1" ]; then + elif [ "$#" -eq 1 ] && (cd "$1" &>{{ Opts::DEVNULL }}); then __zoxide_cd "$1" else local __zoxide_result diff --git a/templates/posix.txt b/templates/posix.txt index 815f770..58921e1 100644 --- a/templates/posix.txt +++ b/templates/posix.txt @@ -79,7 +79,7 @@ __zoxide_z() { echo 'zoxide: $OLDPWD is not set' return 1 fi - elif [ "$#" -eq 1 ] && [ -d "$1" ]; then + elif [ "$#" -eq 1 ] && (cd "$1" >{{ Opts::DEVNULL }}) 2>&1; then __zoxide_cd "$1" else __zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}" diff --git a/templates/zsh.txt b/templates/zsh.txt index acb900b..fdfaf73 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -59,7 +59,9 @@ function __zoxide_z() { echo "zoxide: \\$OLDPWD is not set" return 1 fi - elif ! { [ "$#" -eq 1 ] && __zoxide_cd "$1" &>{{ Opts::DEVNULL }}; }; then + elif [ "$#" -eq 1 ] && (cd "$1" &>{{ Opts::DEVNULL }}) then + __zoxide_cd "$1" + else local __zoxide_result __zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result" fi