Created
September 25, 2018 16:32
-
-
Save algal/c0f2d69473bf66aebba052bb30f96b47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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