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