Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jlebon opened this issue Mar 19, 2024 · 1 comment
Closed

Comments

@jlebon
Copy link

jlebon commented Mar 19, 2024

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.

@ajeetdsouza
Copy link
Owner

ajeetdsouza commented May 5, 2024

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants