Skip to content

Instantly share code, notes, and snippets.

@gregsexton
Created July 11, 2015 17:50
Show Gist options
  • Save gregsexton/dd2d6c304d06fc3e6833 to your computer and use it in GitHub Desktop.
Save gregsexton/dd2d6c304d06fc3e6833 to your computer and use it in GitHub Desktop.
Company backend for completing eshell history
(defun company-eshell-history (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-eshell-history))
(prefix (and (eq major-mode 'eshell-mode)
(let ((word (company-grab-word)))
(save-excursion
(eshell-bol)
(and (looking-at-p (s-concat word "$")) word)))))
(candidates (remove-duplicates
(->> (ring-elements eshell-history-ring)
(remove-if-not (lambda (item) (s-prefix-p arg item)))
(mapcar 's-trim))
:test 'string=))
(sorted t)))
(add-to-list 'company-backends 'company-eshell-history)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment