Eshell: Remove duplicates in history

master
Pierre Neidhardt 2019-02-05 22:45:17 +01:00
parent 4392607e8e
commit 368d2e3d8e
1 changed files with 12 additions and 1 deletions

View File

@ -201,7 +201,7 @@
;;; History
;;; Filter out space-beginning commands from history.
;;; TODO: history/command hook: trim spaces. Check `eshell-rewrite-command-hook'.
;;; TODO: history: do not save failed Eshell commands (See `eshell-last-command-status')
;;; REVIEW: history: do not save failed Eshell commands (See `eshell-last-command-status')
;;; Eshell commands always return 0.
(setq eshell-input-filter
(lambda (str)
@ -228,6 +228,17 @@
(setq eshell-history-ring ambrevar/eshell-history-global-ring))
(add-hook 'eshell-mode-hook 'ambrevar/eshell-hist-use-global-history)
(defun ambrevar/eshell-history-remove-duplicates ()
"Remove duplicates of last command in history.
This should be faster then `seq-uniq'."
(let ((first (ring-ref eshell-history-ring 0))
(index 1))
(while (<= index (1- (ring-length eshell-history-ring)))
(if (string= first (ring-ref eshell-history-ring index))
(ring-remove eshell-history-ring index)
(setq index (1+ index))))))
(add-hook 'eshell-pre-command-hook 'ambrevar/eshell-history-remove-duplicates)
;;; Spawning
(defun ambrevar/eshell-or-new-session (&optional arg)
"Create an interactive Eshell buffer.