Skip to content

Instantly share code, notes, and snippets.

@ethan5422
Last active January 4, 2016 08:09
Show Gist options
  • Save ethan5422/8593794 to your computer and use it in GitHub Desktop.
Save ethan5422/8593794 to your computer and use it in GitHub Desktop.
eshell-insert-last-word
(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