ajeetdsouza/zoxide

RFE: support a variant of `_ZO_ECHO` that only echoes if zoxide logic kicked in

Closed this issue · 1 comments

I'm using --cmd cd to make zoxide take over my cd.

It would be helpful when navigating around to more easily tell when zoxide jumped to a directory rather than just having passed a valid path to cd into.

E.g. if I cd foo, if there actually is a foo directory, then don't echo. If there isn't but one was found in the database, then do echo. By only printing in the latter case, it makes it easier to tell when zoxide logic kicked in and whether that matched my expectation. For example, if I typo'ed a local directory, I would be surprised to see the echo and realized what had happened more easily.

zoxide is designed to be hackable. It's fairly easy to build something like this by replacing the underlying command - you inspect the result of zoxide init <your shell>, and change it to whatever you like.

For example, for zsh:

function __zoxide_z() {
    # shellcheck disable=SC2199
    if [[ "$#" -eq 0 ]]; then
        __zoxide_cd ~
    elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
        __zoxide_cd "$1"
    else
        \builtin local result
        # shellcheck disable=SC2312
-        result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" && __zoxide_cd "${result}"
+        result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" && \
+            echo "{result}" && \
+            __zoxide_cd "${result}"
    fi
}