* lisp/bandali-gnus.el: Some automatic processing for incoming spam
[~bandali/configs] / lisp / bandali-dired.el
1 ;;; bandali-dired.el --- bandali's dired setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: files
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My dired setup and customizations.
24
25 ;;; Code:
26
27 (use-package dired
28 :config
29 (setq dired-dwim-target t
30 dired-listing-switches "-alh"
31 ls-lisp-use-insert-directory-program nil)
32
33 ;; easily diff 2 marked files
34 ;; https://oremacs.com/2017/03/18/dired-ediff/
35 (defun dired-ediff-files ()
36 (interactive)
37 (require 'dired-aux)
38 (defvar ediff-after-quit-hook-internal)
39 (let ((files (dired-get-marked-files))
40 (wnd (current-window-configuration)))
41 (if (<= (length files) 2)
42 (let ((file1 (car files))
43 (file2 (if (cdr files)
44 (cadr files)
45 (read-file-name
46 "file: "
47 (dired-dwim-target-directory)))))
48 (if (file-newer-than-file-p file1 file2)
49 (ediff-files file2 file1)
50 (ediff-files file1 file2))
51 (add-hook 'ediff-after-quit-hook-internal
52 (lambda ()
53 (setq ediff-after-quit-hook-internal nil)
54 (set-window-configuration wnd))))
55 (error "no more than 2 files should be marked"))))
56
57 (require 'dired-x)
58 (setq dired-guess-shell-alist-user
59 '(("\\.pdf\\'" "evince" "zathura" "okular")
60 ("\\.doc\\'" "libreoffice")
61 ("\\.docx\\'" "libreoffice")
62 ("\\.ppt\\'" "libreoffice")
63 ("\\.pptx\\'" "libreoffice")
64 ("\\.xls\\'" "libreoffice")
65 ("\\.xlsx\\'" "libreoffice")
66 ("\\.flac\\'" "mpv")))
67 :bind (:map dired-mode-map
68 ("b" . dired-up-directory)
69 ("E" . dired-ediff-files)
70 ("e" . dired-toggle-read-only)
71 ("\\" . dired-hide-details-mode)
72 ("z" . (lambda ()
73 (interactive)
74 (b/dired-start-process "zathura"))))
75 :hook (dired-mode . dired-hide-details-mode))
76
77 (provide 'bandali-dired)
78 ;;; bandali-dired.el ends here