Last active
January 4, 2016 08:09
-
-
Save ethan5422/8593794 to your computer and use it in GitHub Desktop.
eshell-insert-last-word
This file contains 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
(defun eshell-last-argument (n m) | |
(let* ((input (substring-no-properties | |
(eshell-previous-input-string (1- m)))) | |
(parse (with-temp-buffer | |
(insert input) | |
(nth (1- n) (reverse (eshell-parse-arguments | |
(point-min) (point-max))))))) | |
(eval parse))) | |
(defun eshell-insert-last-word (n) | |
(interactive "p") | |
(if (eq last-command this-command) | |
(let ((m (get 'eshell-insert-last-word 'pre-m)) | |
(pre-p (get 'eshell-insert-last-word 'pre-p))) | |
(delete-region pre-p (point)) | |
(put 'eshell-insert-last-word 'pre-m (1+ m)) | |
(put 'eshell-insert-last-word 'pre-p (point)) | |
(insert (eshell-last-argument n (1+ m)))) | |
(put 'eshell-insert-last-word 'pre-m 1) | |
(put 'eshell-insert-last-word 'pre-p (point)) | |
(insert (eshell-last-argument n 1)))) | |
(add-hook 'eshell-mode-hook | |
(lambda () | |
(define-key eshell-mode-map [?\M-.] 'eshell-insert-last-word))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment