;;; thanos-dired.el --- Dired configuration -*- lexical-binding: t; -*- ;; Copyright (C) 2023 Thanos Apollo ;; Author: Thanos Apollo ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (require 'dired) (require 'nerd-icons-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 using feh." (interactive) (call-process-shell-command (format "feh --bg-scale %s" (dired-get-filename)) nil 0)) (defun dired-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))))) (defun dired-delete-file-match () "Delete all files inside directory except match." (interactive) (let* ((directory (read-directory-name "Select directory: ")) (files (directory-files directory t)) (match (read-string "Delete files that match: "))) (dolist (file files) (when (string-match-p match file) (dired-delete-file file t))))) (defun dired-rename-capitalize-file () "Capitalize the base name of the file at point in a dired buffer." (interactive) (let* ((file (dired-get-file-for-visit)) (new-file (capitalize (file-name-nondirectory file)))) (if (string-prefix-p "." file) (message "Skipping file starting with '.'") (progn (rename-file file (concat (file-name-directory file) new-file)) (revert-buffer) (message "Renamed %s to %s" file new-file))))) (define-key dired-mode-map (kbd "b") 'dired-up-directory) (define-key dired-mode-map (kbd "v") 'dired-watch-video) (define-key dired-mode-map (kbd "z") 'wdired-change-to-wdired-mode) (define-key dired-mode-map (kbd "C-c w") 'dired-set-wallpaper) (define-key global-map (kbd "C-c d") 'dired-delete-files-except) (add-hook 'dired-mode-hook 'nerd-icons-dired-mode) (setf nerd-icons-dired-v-adjust 0.10) (provide 'thanos-dired) ;;; thanos-dired.el ends here