Last active
August 9, 2026 01:07
-
-
Save benja2998/eea62f32d5886e48fdeb102eaf6be7e1 to your computer and use it in GitHub Desktop.
Zoxide for eshell how to get zoxide for eshell zoxide eshell emacs zoxide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun eshell/z (&optional &rest ARGS) | |
| "Zoxide implementation for Eshell. Optionally takes in ARGS, which will be passed to Zoxide" | |
| (interactive) | |
| (let* ((args (if ARGS | |
| (eshell-list-to-string (flatten-tree ARGS)) | |
| (getenv "HOME"))) | |
| (output (string-trim | |
| (shell-command-to-string | |
| (concat "zoxide query " args))))) | |
| (cond | |
| ;; if it is -, go back | |
| ((string-equal args "-") | |
| (eshell/cd "-")) | |
| ;; if it exists, just cd to it and try to add it | |
| ((file-directory-p args) | |
| (shell-command-to-string | |
| (concat "zoxide add " args)) | |
| (eshell/cd args)) | |
| ;; until I can find a better way to check for it finding nothing, | |
| ;; this relies on zoxide's output format staying the same | |
| ;; | |
| ;; this one might be redundant with the clause above, | |
| ;; but I will keep it just to be safe | |
| ((string-equal output "zoxide: no match found") | |
| (shell-command-to-string | |
| (concat "zoxide add " args)) | |
| (eshell/cd args)) | |
| ;; if zoxide found it, cd to it | |
| (t | |
| (eshell/cd output))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment