Run EXWM on langa too
[~bandali/configs] / .emacs.d / lisp / bandali-dired.el
CommitLineData
4c05c418
AB
1;;; bandali-dired.el --- bandali's dired setup -*- lexical-binding: t; -*-
2
78d731e1 3;; Copyright (C) 2018-2022 Amin Bandali
4c05c418
AB
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 27(with-eval-after-load 'dired
c2dbdaef 28 ;; (require 'ls-lisp)
78d731e1 29 (setq
0596e3cf 30 dired-dwim-target t
c2dbdaef 31 dired-listing-switches "-alh --group-directories-first"
0596e3cf
AB
32 dired-recent-directories-file (b/var "dired-recent-directories.el")
33 ls-lisp-dirs-first t
34 ls-lisp-use-insert-directory-program nil)
679463c6 35
3e61146e 36 (declare-function dired-dwim-target-directory "dired-aux")
679463c6
AB
37 ;; easily diff 2 marked files
38 ;; https://oremacs.com/2017/03/18/dired-ediff/
39 (defun dired-ediff-files ()
40 (interactive)
41 (require 'dired-aux)
42 (defvar ediff-after-quit-hook-internal)
43 (let ((files (dired-get-marked-files))
44 (wnd (current-window-configuration)))
45 (if (<= (length files) 2)
46 (let ((file1 (car files))
47 (file2 (if (cdr files)
48 (cadr files)
49 (read-file-name
50 "file: "
51 (dired-dwim-target-directory)))))
52 (if (file-newer-than-file-p file1 file2)
53 (ediff-files file2 file1)
54 (ediff-files file1 file2))
55 (add-hook 'ediff-after-quit-hook-internal
56 (lambda ()
57 (setq ediff-after-quit-hook-internal nil)
58 (set-window-configuration wnd))))
59 (error "no more than 2 files should be marked"))))
60
927b50b7
AB
61 (defun b/dired-start-process (program &optional args)
62 "Open current file with a PROGRAM."
63 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS
64 ;; can be nil, so remove it).
65 (declare-function dired-get-file-for-visit "dired")
66 (apply #'b/start-process
67 program
68 (remove nil (list args (dired-get-file-for-visit)))))
69
c84be134
AB
70 ;; local key bindings
71 (define-key dired-mode-map (kbd "b") #'dired-up-directory)
72 (define-key dired-mode-map (kbd "E") #'dired-ediff-files)
73 (define-key dired-mode-map (kbd "e") #'dired-toggle-read-only)
74 (define-key dired-mode-map (kbd "\\") #'dired-hide-details-mode)
75 (define-key dired-mode-map (kbd "z")
76 (lambda ()
77 (interactive)
78 (b/dired-start-process "zathura")))
79
679463c6 80 (require 'dired-x)
78d731e1
AB
81 (setq
82 dired-guess-shell-alist-user
83 '(("\\.pdf\\'" "evince" "zathura" "okular")
84 ("\\.doc\\'" "libreoffice")
85 ("\\.docx\\'" "libreoffice")
86 ("\\.ppt\\'" "libreoffice")
87 ("\\.pptx\\'" "libreoffice")
88 ("\\.xls\\'" "libreoffice")
89 ("\\.xlsx\\'" "libreoffice")
90 ("\\.flac\\'" "mpv"))))
c84be134
AB
91;; hooks
92(add-hook 'dired-mode-hook #'dired-hide-details-mode)
679463c6
AB
93
94(provide 'bandali-dired)
4c05c418 95;;; bandali-dired.el ends here