From 5253c9fa64de34bbef86c1ee8683924592338651 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 15 Aug 2023 05:01:47 +0300 Subject: emacs: Update dired functions Redo docstrings and shell commands Add delete-files-except function --- emacs.org | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'emacs.org') diff --git a/emacs.org b/emacs.org index ceae17c..0ab6eea 100755 --- a/emacs.org +++ b/emacs.org @@ -318,16 +318,31 @@ Generate a random password between 20 and 40 characters * Dired ** Functions #+begin_src emacs-lisp + (require 'dired) + (defun dired-watch-video () + "Watch play file with mpv." (interactive) (call-process-shell-command (format "mpv \"%s\"" (dired-get-filename)) nil 0)) (defun dired-set-wallpaper () - "Set NAME as wallpaper." - (interactive) - (call-process-shell-command - (format "feh --bg-scale %s" (dired-get-filename) nil 0))) + "Set NAME as wallpaper using feh." + (interactive) + (call-process-shell-command + (format "feh --bg-scale %s" (dired-get-filename)) nil 0)) + + (defun delete-files-except () + "Delete all files inside directory except match." + (interactive) + (let* ((directory (read-directory-name "Select directory: ")) + (files (directory-files directory t)) + (except-match (read-string "Except the ones that have: "))) + (dolist (file files) + (unless (or (string= "." (substring file -1)) + (string= ".." (substring file -2)) + (string-match except-match file) + (dired-delete-file file t)))))) #+end_src ** Keybindings #+begin_src emacs-lisp -- cgit v1.2.3