From ee9e5917736abb082379c371dff11a0d29c417d0 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Wed, 31 Oct 2018 23:23:54 -0400 Subject: [PATCH] added function to navigate to mounted devices --- conf.org | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/conf.org b/conf.org index 89268ca..475ba8a 100644 --- a/conf.org +++ b/conf.org @@ -307,6 +307,13 @@ desktop file exec directive." (let* ((cmd (concat "file --mime-type -b " file)) (mt (shell-command-to-string cmd))) (replace-regexp-in-string "\n\\'" "" mt))) + +(defvar nd/device-mount-dir (concat "/media/" (user-login-name))) + +(defun nd/get-mounted-directories (&optional mount-path) + "Scan MOUNT-PATH (defaults to /media/$USER for devices that have +been mounted by udevil." + (seq-filter #'file-directory-p (directory-files nd/device-mount-dir t "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)"))) #+END_SRC ** interactive #+BEGIN_SRC emacs-lisp @@ -1905,6 +1912,24 @@ By default dired uses =ls -whatever= to get its output. This does not have recur :config (setq dired-du-size-format t)) #+END_SRC +*** mounted devices +All my devices should be mounted in =/media/$USER=, so implement a simple help search to navigate this directory after mounting with udevil. +#+BEGIN_SRC emacs-lisp +(defun nd/dired-mounted-devices () + "Navigate to a directory for a mounted device." + (interactive) + (let ((dev (nd/get-mounted-directories))) + (if dev + (helm + :sources + (helm-build-sync-source "Devices" + :candidates (mapcar (lambda (d) `(,(file-name-base d) . ,d)) dev) + :action + '(("Open" . (lambda (s) (find-file s))) + ("Unmount" . (lambda (s) (start-process "unmount" nil "udevil" "unmount" s))))) + :buffer "*helm device buffer*") + (message "No devices mounted")))) +#+END_SRC ** mu4e *** basic #+BEGIN_SRC emacs-lisp