added function to navigate to mounted devices

This commit is contained in:
ndwarshuis 2018-10-31 23:23:54 -04:00
parent 2844630f8c
commit ee9e591773
1 changed files with 25 additions and 0 deletions

View File

@ -307,6 +307,13 @@ desktop file exec directive."
(let* ((cmd (concat "file --mime-type -b " file)) (let* ((cmd (concat "file --mime-type -b " file))
(mt (shell-command-to-string cmd))) (mt (shell-command-to-string cmd)))
(replace-regexp-in-string "\n\\'" "" mt))) (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 #+END_SRC
** interactive ** interactive
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
@ -1905,6 +1912,24 @@ By default dired uses =ls -whatever= to get its output. This does not have recur
:config :config
(setq dired-du-size-format t)) (setq dired-du-size-format t))
#+END_SRC #+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 ** mu4e
*** basic *** basic
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp