Created
June 10, 2025 07:23
-
-
Save DivineDominion/65053a7b8bd239632b8ecfbbad9fbd7a to your computer and use it in GitHub Desktop.
consult.el function to find files using macOS Spotlight
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 consult--mdfind-builder (input) | |
"Build command line from INPUT." | |
(pcase-let ((`(,arg . ,opts) (consult--command-split input))) | |
(unless (string-blank-p arg) | |
(cons (append '("mdfind") (list arg) opts) | |
(apply-partially #'consult--highlight-regexps | |
(mapcar #'regexp-quote (split-string arg)) | |
t))))) | |
(defun consult-mdfind (&optional initial) | |
"Search with `mdfind` for files which match input given INITIAL input. | |
The input is passed directly to the mdfind process. The search is started | |
asynchronously, similar to `consult-grep`. See `consult-grep` for more | |
details regarding the asynchronous search." | |
(interactive) | |
(find-file (consult--read | |
(consult--process-collection #'consult--mdfind-builder | |
:transform (consult--async-map (lambda (x) (string-remove-prefix "./" x))) | |
:highlight t :file-handler t) | |
:prompt "Spotlight Search: " | |
:sort nil | |
:require-match t | |
:initial initial | |
:add-history (thing-at-point 'filename) | |
:category 'file | |
:history '(:input consult--find-history)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment