summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-03-27 02:08:26 -0400
committerKyle Meyer <kyle@kyleam.com>2015-03-27 02:08:26 -0400
commit95fe32b0f8dd3c0f5394c484cfb62ef7e026c489 (patch)
treefc873af2e50a0811e943b40f2db9f1e38fb7049c
parentaf9496b115a855323223ecf4e2cedc2daf052c23 (diff)
downloademacs.d-95fe32b0f8dd3c0f5394c484cfb62ef7e026c489.tar.gz
Add command magit-insert-staged-file
-rw-r--r--lisp/init-git.el16
1 files changed, 16 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index d8ae3d3..db92c2e 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -209,6 +209,21 @@ the commit buffer. And no dinging."
(match-string 2))
(magit-show-commit it t))))
+(defun km/magit-insert-staged-file (&optional no-directory)
+ "Select staged file to insert.
+This is useful for referring to file names in commit messages.
+By default, the path for the file name is relative to the top
+directory of the repository. Remove the directory component from
+the file name if NO-DIRECTORY is non-nil."
+ (interactive "P")
+ (let* ((default-directory (magit-get-top-dir))
+ (files (magit-staged-files))
+ (file (if (= 1 (length files))
+ (car files)
+ (completing-read "Staged file: " (magit-staged-files)
+ nil t))))
+ (insert (if no-directory (file-name-nondirectory file) file))))
+
(define-key ctl-x-4-map "g" 'magit-find-file-other-window)
(define-key km/file-map "g" 'magit-find-file)
@@ -233,6 +248,7 @@ the commit buffer. And no dinging."
(define-key km/git-map "C" 'km/magit-show-project-commit-under-point)
(define-key km/git-map "e" 'km/magit-commit-extend-all)
(define-key km/git-map "p" 'km/magit-pin-file)
+ (define-key km/git-map "s" 'km/magit-insert-staged-file)
(define-key km/git-map "u" 'km/magit-auto-commit))
(after 'magit-log