Skip to content

Instantly share code, notes, and snippets.

@quantumish
Last active January 13, 2025 21:50
Show Gist options
  • Select an option

  • Save quantumish/643314fdbdb992af66a88fdeb3bd1ead to your computer and use it in GitHub Desktop.

Select an option

Save quantumish/643314fdbdb992af66a88fdeb3bd1ead to your computer and use it in GitHub Desktop.
Simple zoxide integration for Emacs
(require 'consult)
(add-hook
'dired-mode-hook
(lambda ()
(call-process-shell-command
(format "zoxide add %s" dired-directory) nil 0)))
(add-hook
'find-file-hook
(lambda ()
(call-process-shell-command
(format "zoxide add %s" (file-name-directory buffer-file-name))
nil 0)))
(defun find-file-with-zoxide ()
(interactive)
(let ((target (consult--read
(consult--process-collection (lambda (x) (list "zoxide" "query" "-l" x)))
:prompt "Zoxide "
:require-match nil
:lookup #'consult--lookup-member
:require-match t
:category 'file
:sort nil)))
(if target
(let ((default-directory (concat target "/")))
(call-interactively 'find-file))
(call-interactively 'find-file))))
@omidmnz
Copy link

omidmnz commented Jan 10, 2025

Used to work great, however after a consult update throws the following message:

CONSULT ERROR: `find-file-with-zoxide' uses the old async API
convention and must be updated.  The `consult--async-*' API has been
updated in a backward-incompatible way.  For details, please see the
Consult CHANGELOG, the relevant git commit message and the docstring
of the `consult--async-pipeline' macro, which describes the updated
API.

I will try to change it to the new pipeline and update here when I find time, in case it isn't updated before I do so.

@quantumish
Copy link
Author

Thanks for pointing this out! I just updated it to use the newer API (although I haven't read the docs very closely - let me know if you experience any weird behavior). Should work now!

@omidmnz
Copy link

omidmnz commented Jan 13, 2025

Thanks. Works like a charm now. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment