Skip to content

Instantly share code, notes, and snippets.

@kanru
Forked from ethan5422/eshell-insert-last-word.el
Last active January 4, 2016 21:29
Show Gist options
  • Save kanru/8680931 to your computer and use it in GitHub Desktop.
Save kanru/8680931 to your computer and use it in GitHub Desktop.
(defun eshell-last-argument (n)
(let* ((input (substring-no-properties
(eshell-previous-input-string (1- n))))
(parse (with-temp-buffer
(insert input)
(car (reverse (eshell-parse-arguments
(point-min) (point-max)))))))
(eval parse)))
(defun eshell-insert-last-word (n)
(interactive "p")
(unless (eq last-command this-command)
(put 'eshell-insert-last-word 'pre-n n)
(put 'eshell-insert-last-word 'pre-p nil))
(let ((n (get 'eshell-insert-last-word 'pre-n))
(pre-p (get 'eshell-insert-last-word 'pre-p)))
(when pre-p
(delete-region pre-p (point)))
(put 'eshell-insert-last-word 'pre-n (1+ n))
(put 'eshell-insert-last-word 'pre-p (point))
(insert (eshell-last-argument n))))
(add-hook 'eshell-mode-hook
(lambda () (define-key eshell-mode-map (kbd "M-.") 'eshell-insert-last-word)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment