Function: dired-copy-filename-as-kill
dired-copy-filename-as-kill is an interactive and byte-compiled
function defined in dired.el.gz.
Signature
(dired-copy-filename-as-kill &optional ARG)
Documentation
Copy names of marked (or next ARG) files into the kill ring.
If there are several names, they will be separated by a space, and file names that have spaces or quote characters in them will be quoted (with double quotes). (When there's a single file, no quoting is done.)
With a zero prefix arg, use the absolute file name of each marked file.
With a prefix value 1, use the names relative to the current project root.
With C-u (universal-argument), use the file name relative to the Dired buffer's
default-directory. (This still may contain slashes if in a subdirectory.)
If on a subdir headerline, use absolute subdirname instead; prefix arg and marked files are ignored in this case.
You can then feed the file name(s) to other commands with C-y (yank).
Probably introduced at or before Emacs version 22.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/dired.el.gz
(defun dired-copy-filename-as-kill (&optional arg)
"Copy names of marked (or next ARG) files into the kill ring.
If there are several names, they will be separated by a space,
and file names that have spaces or quote characters in them will
be quoted (with double quotes). (When there's a single file, no
quoting is done.)
With a zero prefix arg, use the absolute file name of each marked file.
With a prefix value 1, use the names relative to the current project root.
With \\[universal-argument], use the file name relative to the Dired buffer's
`default-directory'. (This still may contain slashes if in a subdirectory.)
If on a subdir headerline, use absolute subdirname instead;
prefix arg and marked files are ignored in this case.
You can then feed the file name(s) to other commands with \\[yank]."
(interactive "P" dired-mode)
(let* ((files
(or (ensure-list (dired-get-subdir))
(if arg
(cond ((eql 0 arg)
(dired-get-marked-files))
((eql 1 arg)
(let ((root (project-root (project-current t))))
(mapcar
(lambda (file) (file-relative-name file root))
(dired-get-marked-files))))
((consp arg)
(dired-get-marked-files t))
(t
(dired-get-marked-files
'no-dir (prefix-numeric-value arg))))
(dired-get-marked-files 'no-dir))))
(string
(if (length= files 1)
(car files)
(mapconcat (lambda (file)
(if (string-match-p "[ \"']" file)
(format "%S" file)
file))
files
" "))))
(unless (string= string "")
(if (eq last-command 'kill-region)
(kill-append string nil)
(kill-new string))
(message "%s" string))))