feat(eshell): add help command & lookup handler

Fix: #6867
Co-authored-by: aikrahguzar <aikrahguzar@users.noreply.github.com>
This commit is contained in:
Henrik Lissner
2025-04-13 02:45:01 -04:00
parent c7ca3ea8cc
commit 5fdffe19db
3 changed files with 21 additions and 0 deletions

View File

@ -28,3 +28,6 @@ For folks with a habit of using \"emacs\" to open files, even in eshell."
"Create a directory then cd into it." "Create a directory then cd into it."
(make-directory dir t) (make-directory dir t)
(eshell/cd dir)) (eshell/cd dir))
;;;###autoload
(defalias 'eshell/help #'+eshell-lookup-documentation)

View File

@ -75,6 +75,21 @@
(insert command) (insert command)
(eshell-send-input nil t)))) (eshell-send-input nil t))))
;; Adapted from `esh-help-run-help'
;;;###autoload
(defun +eshell-lookup-documentation (cmd)
"Show help for CMD (a shell command or elisp function)."
(cond ((eshell-find-alias-function cmd)
(always (helpful-callable (eshell-find-alias-function cmd))))
((and (or (and (string-match-p "^\\*." cmd)
(cl-callf substring cmd 1))
(eshell-search-path cmd))
(zerop (car (doom-call-process manual-program cmd))))
(always (display-buffer (man cmd))))
((functionp (intern cmd))
(helpful-callable (intern cmd)) t)
((user-error "Couldn't find man pages or elisp documentation for %S" cmd))))
;; ;;
;;; Commands ;;; Commands

View File

@ -55,6 +55,9 @@ You should use `set-eshell-alias!' to change this.")
;;; Packages ;;; Packages
(after! eshell ; built-in (after! eshell ; built-in
(set-lookup-handlers! 'eshell-mode
:documentation #'+eshell-lookup-documentation)
(setq eshell-banner-message (setq eshell-banner-message
'(format "%s %s\n" '(format "%s %s\n"
(propertize (format " %s " (string-trim (buffer-name))) (propertize (format " %s " (string-trim (buffer-name)))