Drop use-package
[~bandali/configs] / lisp / bandali-dired.el
CommitLineData
4c05c418
AB
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
c84be134
AB
27(with-eval-after-load 'dired
28 (csetq dired-dwim-target t
29 dired-listing-switches "-alh"
30 ls-lisp-dirs-first t
31 ls-lisp-use-insert-directory-program nil)
679463c6 32
3e61146e 33 (declare-function dired-dwim-target-directory "dired-aux")
679463c6
AB
34 ;; easily diff 2 marked files
35 ;; https://oremacs.com/2017/03/18/dired-ediff/
36 (defun dired-ediff-files ()
37 (interactive)
38 (require 'dired-aux)
39 (defvar ediff-after-quit-hook-internal)
40 (let ((files (dired-get-marked-files))
41 (wnd (current-window-configuration)))
42 (if (<= (length files) 2)
43 (let ((file1 (car files))
44 (file2 (if (cdr files)
45 (cadr files)
46 (read-file-name
47 "file: "
48 (dired-dwim-target-directory)))))
49 (if (file-newer-than-file-p file1 file2)
50 (ediff-files file2 file1)
51 (ediff-files file1 file2))
52 (add-hook 'ediff-after-quit-hook-internal
53 (lambda ()
54 (setq ediff-after-quit-hook-internal nil)
55 (set-window-configuration wnd))))
56 (error "no more than 2 files should be marked"))))
57
c84be134
AB
58 ;; local key bindings
59 (define-key dired-mode-map (kbd "b") #'dired-up-directory)
60 (define-key dired-mode-map (kbd "E") #'dired-ediff-files)
61 (define-key dired-mode-map (kbd "e") #'dired-toggle-read-only)
62 (define-key dired-mode-map (kbd "\\") #'dired-hide-details-mode)
63 (define-key dired-mode-map (kbd "z")
64 (lambda ()
65 (interactive)
66 (b/dired-start-process "zathura")))
67
679463c6 68 (require 'dired-x)
c84be134
AB
69 (csetq dired-guess-shell-alist-user
70 '(("\\.pdf\\'" "evince" "zathura" "okular")
71 ("\\.doc\\'" "libreoffice")
72 ("\\.docx\\'" "libreoffice")
73 ("\\.ppt\\'" "libreoffice")
74 ("\\.pptx\\'" "libreoffice")
75 ("\\.xls\\'" "libreoffice")
76 ("\\.xlsx\\'" "libreoffice")
77 ("\\.flac\\'" "mpv"))))
78;; hooks
79(add-hook 'dired-mode-hook #'dired-hide-details-mode)
679463c6
AB
80
81(provide 'bandali-dired)
4c05c418 82;;; bandali-dired.el ends here