Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File path to clipboard in Emacs

Tags:

emacs

What is the most simple way to send current full file name with file path to clipboard?

What I am using now is messages buffer: I copy file name that appears there after saving a file. But, I suppose, there should be much more simple way.

like image 807
Dmytro Kuznetsov Avatar asked Mar 10 '10 12:03

Dmytro Kuznetsov


3 Answers

Why no one tell the simple solution.

Just go to your dired buffer then press 0 w or C-u 0 w.

This will call dired-copy-filename-as-kill which gives you full path of a file. If you want current dir, just delete the file at the end of it or you can use the function below, then bind it to any key you like.

(defun my/dired-copy-dirname-as-kill ()
  "Copy the current directory into the kill ring."
  (interactive)
  (kill-new default-directory))

PS: personally I go to current directory from file buffer using dired-jump

like image 55
azzamsa Avatar answered Nov 18 '22 08:11

azzamsa


I use this:

(defun my-put-file-name-on-clipboard ()
  "Put the current file name on the clipboard"
  (interactive)
  (let ((filename (if (equal major-mode 'dired-mode)
                      default-directory
                    (buffer-file-name))))
    (when filename
      (with-temp-buffer
        (insert filename)
        (clipboard-kill-region (point-min) (point-max)))
      (message filename))))
like image 26
scottfrazer Avatar answered Nov 18 '22 08:11

scottfrazer


In Emacs Prelude I use:

(defun prelude-copy-file-name-to-clipboard ()
  "Copy the current buffer file name to the clipboard."
  (interactive)
  (let ((filename (if (equal major-mode 'dired-mode)
                      default-directory
                    (buffer-file-name))))
    (when filename
      (kill-new filename)
      (message "Copied buffer file name '%s' to the clipboard." filename))))
like image 27
Bozhidar Batsov Avatar answered Nov 18 '22 08:11

Bozhidar Batsov