[Utils] Command to display dired buffer of custom file list

This commit is contained in:
Daniel - 2019-06-08 13:04:05 +02:00
parent 7bfdb92259
commit 0e3ad47943
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
2 changed files with 28 additions and 1 deletions

View File

@ -583,7 +583,8 @@ search commands like `db/helm-shortcuts."
db/lookup-smime-key
db/org-onenote-open
db/org-outlook-open
db/org-rfc-open))
db/org-rfc-open
db/dired-from-shell-command))
(use-package hydra
:commands (defhydra))

View File

@ -326,6 +326,32 @@ If found, imports the certificate via gpgsm."
(message "Successfully imported certificate for <%s>" mail)
(error "Could not import certificate for <%s>" mail))))))))
;; https://emacs.stackexchange.com/questions/3089/how-can-i-create-a-dired-buffer-listing-all-open-files
;; https://emacs.stackexchange.com/questions/2567/programmatically-insert-files-into-dired-buffer
(defun db/dired-from-shell-command (command &optional directory)
"Run COMMAND in DIRECTORY and display resulting list of files via `dired.
COMMAND must be a shell command that produces a list of files as
output, separated by \\n, when called with
`shell-command-to-string. DIRECTORY defaults to
`default-directory."
(interactive "sCommand: ")
(when (and directory (not (directory-name-p directory)))
(user-error "Value for DIRECTORY is not a directory name: %s"
directory))
(let* ((default-directory (or directory default-directory))
(list-of-files (cl-remove-if-not
(lambda (entry)
(and (not (string-empty-p entry))
(file-exists-p entry)
(file-readable-p entry)))
(split-string (shell-command-to-string command)
"\n"))))
(if (null list-of-files)
(user-error "No files to display, aborting")
(dired (cons (format "Output of `%s" command)
list-of-files)))))
;;; helm configuration