about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-05-28 20:47:58 -0500
committerCase Duckworth2021-05-28 20:47:58 -0500
commit8fd98de30046174a6f0c2960a5c7b32252809912 (patch)
treecae7ecb5ac7883b265843a3df42db470f5967280
parentMove defun into hook definition (diff)
downloademacs-8fd98de30046174a6f0c2960a5c7b32252809912.tar.gz
emacs-8fd98de30046174a6f0c2960a5c7b32252809912.zip
Add eshell last argument
https://old.reddit.com/r/emacs/comments/nlefvx/weekly_tips_and_tricks/gzpng5o/
-rw-r--r--init.el40
1 files changed, 39 insertions, 1 deletions
diff --git a/init.el b/init.el index 4c3bcdb..8d18dd9 100644 --- a/init.el +++ b/init.el
@@ -314,7 +314,45 @@
314 (define-key eshell-mode-map (kbd "C-d") 314 (define-key eshell-mode-map (kbd "C-d")
315 #'eshell-quit-or-delete-char) 315 #'eshell-quit-or-delete-char)
316 (when (boundp 'simple-modeline--mode-line) 316 (when (boundp 'simple-modeline--mode-line)
317 (setq mode-line-format '(:eval simple-modeline--mode-line)))))) 317 (setq mode-line-format '(:eval simple-modeline--mode-line)))))
318
319 (with-eval-after-load 'eshell
320 ;; Record arguments
321 (defvar my-eshell-arg-history nil)
322 (defvar my-eshell-arg-history-index nil)
323 (add-to-list 'savehist-additional-variables 'my-eshell-arg-history)
324
325 (defun my-eshell-record-args (&rest _)
326 "Record unique arguments onto the front of `my-eshell-arg-history'."
327 (setq my-eshell-arg-history
328 (cl-loop with history = my-eshell-arg-history
329 for arg in (reverse eshell-last-arguments)
330 do (setq history (cons arg (remove arg history)))
331 finally return history)))
332
333 (defun my-eshell-insert-prev-arg ()
334 "Insert an argument from `my-eshell-arg-history' at point."
335 (interactive)
336 (if (eq last-command 'my-eshell-insert-prev-arg)
337 (progn
338 (let ((pos (point)))
339 (eshell-backward-argument 1)
340 (delete-region (point) pos))
341 (if-let ((text (nth my-eshell-arg-history-index
342 my-eshell-arg-history)))
343 (progn
344 (insert text)
345 (cl-incf my-eshell-arg-history-index))
346 (insert (cl-first my-eshell-arg-history))
347 (setq my-eshell-arg-history-index 1)))
348 (insert (cl-first my-eshell-arg-history))
349 (setq my-eshell-arg-history-index 1)))
350
351 (add-hook 'eshell-mode-hook
352 (lambda ()
353 (add-hook 'eshell-post-command-hook
354 #'my-eshell-record-args nil t)
355 (local-set-key (kbd "M-.") #'my-eshell-insert-prev-arg)))))
318 356
319(setup eww 357(setup eww
320 (:option eww-search-prefix "https://duckduckgo.com/html?q=" 358 (:option eww-search-prefix "https://duckduckgo.com/html?q="