Eshell: Add support for auto-suggestions
parent
a9b618882f
commit
ae5c474d5f
|
@ -189,6 +189,7 @@ See `eshell' for the numeric prefix ARG."
|
||||||
(switch-to-buffer (car last))
|
(switch-to-buffer (car last))
|
||||||
(eshell (or arg t))))))
|
(eshell (or arg t))))))
|
||||||
|
|
||||||
|
;;; Completion
|
||||||
(when (require 'bash-completion nil t)
|
(when (require 'bash-completion nil t)
|
||||||
(defun eshell-bash-completion ()
|
(defun eshell-bash-completion ()
|
||||||
(while (pcomplete-here
|
(while (pcomplete-here
|
||||||
|
@ -199,6 +200,13 @@ See `eshell' for the numeric prefix ARG."
|
||||||
|
|
||||||
(when (and (executable-find "fish")
|
(when (and (executable-find "fish")
|
||||||
(require 'fish-completion nil t))
|
(require 'fish-completion nil t))
|
||||||
(fish-completion-eshell-global-toggle))
|
(fish-completion-eshell-toggle-globally))
|
||||||
|
|
||||||
|
;;; Auto-suggestion
|
||||||
|
(when (require 'package-eshell-autosuggest)
|
||||||
|
(add-hook 'eshell-mode-hook 'company-mode)
|
||||||
|
(when (require 'helm-config nil t)
|
||||||
|
(define-key company-active-map (kbd "M-p") 'helm-eshell-history))
|
||||||
|
(add-hook 'eshell-mode-hook 'eshell-setup-autosuggest))
|
||||||
|
|
||||||
(provide 'init-eshell)
|
(provide 'init-eshell)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
(require 'company)
|
||||||
|
|
||||||
|
(defun company-eshell-autosuggest-candidates (prefix)
|
||||||
|
(let* ((history
|
||||||
|
(cl-remove-duplicates
|
||||||
|
(mapcar (lambda (str)
|
||||||
|
(string-trim (substring-no-properties str)))
|
||||||
|
(ring-elements eshell-history-ring))
|
||||||
|
:from-end t
|
||||||
|
:test #'string=))
|
||||||
|
(most-similar (cl-find-if
|
||||||
|
(lambda (str)
|
||||||
|
(string-prefix-p prefix str))
|
||||||
|
history)))
|
||||||
|
(when most-similar
|
||||||
|
`(,most-similar))))
|
||||||
|
|
||||||
|
(defun company-eshell-autosuggest--prefix ()
|
||||||
|
(let ((prefix
|
||||||
|
(string-trim-left
|
||||||
|
(buffer-substring-no-properties
|
||||||
|
(save-excursion
|
||||||
|
(eshell-bol))
|
||||||
|
(save-excursion (end-of-line) (point))))))
|
||||||
|
(if (not (string-empty-p prefix))
|
||||||
|
prefix
|
||||||
|
'stop)))
|
||||||
|
|
||||||
|
(defun company-eshell-autosuggest (command &optional arg &rest ignored)
|
||||||
|
(interactive (list 'interactive))
|
||||||
|
(cl-case command
|
||||||
|
(interactive (company-begin-backend 'company-eshell))
|
||||||
|
(prefix (and (eq major-mode 'eshell-mode)
|
||||||
|
(company-eshell-autosuggest--prefix)))
|
||||||
|
(candidates (company-eshell-autosuggest-candidates arg))))
|
||||||
|
|
||||||
|
(defun eshell-setup-autosuggest ()
|
||||||
|
(setq-local company-idle-delay 0.5)
|
||||||
|
(setq-local company-backends '(company-eshell-autosuggest))
|
||||||
|
(setq-local company-frontends '(company-preview-frontend)))
|
||||||
|
|
||||||
|
(provide 'package-eshell-autosuggest)
|
Loading…
Reference in New Issue