From b50ee1d9ea0b696221ee40df5cad95785a711409 Mon Sep 17 00:00:00 2001 From: Peter Solodov Date: Wed, 14 Feb 2024 18:46:39 -0500 Subject: [PATCH] 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. --- templates/bash.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/bash.txt b/templates/bash.txt index aeec524..8a6bdb9 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -102,7 +102,13 @@ function __zoxide_zi() { \builtin unalias {{cmd}} &>/dev/null || \builtin true function {{cmd}}() { - __zoxide_z "$@" + if [[ $# -eq 2 && "$1" == "--" && -d $2 ]]; then + # This is how cd is called when bash's autocd option is set. To get the + # directory-changing behavior first argument must be skipped. + __zoxide_z "${@:2}" + else + __zoxide_z "$@" + fi } \builtin unalias {{cmd}}i &>/dev/null || \builtin true