Skip to content

Instantly share code, notes, and snippets.

@algal
Created September 25, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save algal/c0f2d69473bf66aebba052bb30f96b47 to your computer and use it in GitHub Desktop.
Save algal/c0f2d69473bf66aebba052bb30f96b47 to your computer and use it in GitHub Desktop.
;; Car salesman, *slapping roof of defun*: this bad boy can fit so much damn file management convenience in it.
(defun kill-buffer-file-name-or-name ()
"Pushes a useful path to the kill ring.
When visiting a file, pushes the file's path. In dired,
pushes the path of the file at point or else the current
directory. In magit, pushes the path of the file at point or else
the repo's root. Otherwise, pushes buffer's name. Displays
whatever was pushed in the message area."
(interactive)
(let ((buffer-name
(escape-spaces
(cond
((equal major-mode 'dired-mode)
(condition-case nil
(dired-get-filename)
(error
(dired-current-directory))))
((equal major-mode 'magit-status-mode)
(concat
(magit-get-top-dir)
(nth 1 (magit-section-path (magit-current-section)))))
((buffer-file-name)
(buffer-file-name))
(t
(buffer-name))))))
(kill-new buffer-name)
(message buffer-name)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment