Copy file name or full path of file from Emacs dired buffer into system clipboard

  |   Source

Simple, insert below code into your ~/.emacs:

;; {{ copy the file-name/full-path in dired buffer into clipboard

;; `w` => copy file name

;; `C-u 0 w` => copy full path

(defadvice dired-copy-filename-as-kill (after dired-filename-to-clipboard activate)
    (insert (current-kill 0))
    (shell-command-on-region (point-min) (point-max)
                              ((eq system-type 'cygwin) "putclip")
                              ((eq system-type 'darwin) "pbcopy")
                              (t "xsel -ib")
  (message "%s => clipboard" (current-kill 0))

It support Cygwin and OSX out of the box. You need install xsel under Linux.

BTW, I suggest installing a clipboard manager like parcellite under Linux to sync the two X clipboards.

Comments powered by Disqus