blob: 74973b13801032d35b6180ef2f80ca54ff218a16 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
;;; thanos-dired.el --- Dired configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Thanos Apollo
;; Author: Thanos Apollo <[email protected]>
;; 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 <https://www.gnu.org/licenses/>.
;;; 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
|