-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathdired-ui.el
More file actions
57 lines (44 loc) · 1.98 KB
/
dired-ui.el
File metadata and controls
57 lines (44 loc) · 1.98 KB
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
;;; dired-ui.el --- Additional or extended dired commands -*- lexical-binding: t -*-
;; Copyright (C) 2025 Matúš Goljer
;; Author: Matúš Goljer <[email protected]>
;; Maintainer: Matúš Goljer <[email protected]>
;; Version: 0.0.1
;; Created: 5th May 2025
;; Package-requires: ((f "0.19.0"))
;; Keywords: files
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'dired)
(require 'f)
;;;###autoload
(defun dired-ui-dired-copy-filename-as-kill (&optional arg)
"Copy name of file at point into the kill ring.
This function works the same as `dired-copy-filename-as-kill' but
adds the prefix option \\[universal-argument] to copy file name
up to the project root as determined by `project-root'.
The behaviour of \\[universal-argument] is changed from the
original function, where it used to copy up to the default
directory of the current buffer, which in case of inserted
subdirectories was the \"main\" directory."
(interactive "P")
(if (consp arg)
(let* ((result (dired-copy-filename-as-kill 0))
(root (project-root (project-current)))
(relative-path (concat "./" (f-relative result root))))
(if (eq last-command 'kill-region)
(kill-append relative-path nil)
(kill-new relative-path)
(message "%s" relative-path)))
(dired-copy-filename-as-kill arg)))
(provide 'dired-ui)
;;; dired-ui.el ends here