Skip to content

Archive

Georges Alkhouri edited this page Sep 19, 2021 · 2 revisions

This site containing archived code.

eshell

(use-feature eshell
  :defer t
  :init
  (progn

    (defun *sys/eshell-auto-end* ()
      "Move point to end of current prompt when switching to insert state."
      (when (and (eq major-mode 'eshell-mode)
                 ;; Not on last line, we might want to edit within it.
                 (not (>= (point) eshell-last-output-end))
                 ;; Not on the last sent command if we use smart-eshell so we can
                 ;; edit it.
                 (not (and shell-enable-smart-eshell
                           (>= (point) eshell-last-input-start)
                           (< (point) eshell-last-input-end))))
        (end-of-buffer)))

    (defun *sys/init-eshell* ()
      "Stuff to do when enabling eshell."
      (setq pcomplete-cycle-completions nil)
      (if (bound-and-true-p linum-mode) (linum-mode -1))
      ;; autojump to prompt line if not on one already
      (add-hook 'evil-insert-state-entry-hook
                '*sys/eshell-auto-end* nil t)
      (add-hook 'evil-hybrid-state-entry-hook
                '*sys/eshell-auto-end* nil t))

    (defun *sys/protect-eshell-prompt* ()
      "Protect Eshell's prompt like Comint's prompts. E.g. `evil-change-whole-line' won't wipe the prompt. This
is achieved by adding the relevant text properties."
      (let ((inhibit-field-text-motion t))
        (add-text-properties
         (point-at-bol)
         (point)
         '(rear-nonsticky t
                          inhibit-line-move-field-capture t
                          field output
                          read-only t
                          front-sticky (field inhibit-line-move-field-capture)))))

    (setq eshell-cmpl-cycle-completions nil
          ;; auto truncate after 20k lines
          eshell-buffer-maximum-lines 20000
          ;; history size
          eshell-history-size 350
          ;; no duplicates in history
          eshell-hist-ignoredups t
          ;; my prompt is easy enough to see
          eshell-highlight-prompt nil
          ;; treat 'echo' like shell echo
          eshell-plain-echo-behavior t
          eshell-scroll-to-bottom-on-input t)

    (add-hook 'eshell-mode-hook #'(lambda () (setq-local global-hl-line-mode nil)))
    (add-hook 'eshell-after-prompt-hook '*sys/protect-eshell-prompt*)
    ;; Why?
    (autoload 'eshell-delchar-or-maybe-eof "em-rebind")
    (add-hook 'eshell-mode-hook '*sys/init-eshell*)
    )
  :config
  (progn

    ;;Why ?
    (require 'esh-opt)
    (require 'em-term)
    (require 'aweshell)
    ;; Work around bug in eshell's preoutput-filter code.
    ;; Eshell doesn't call preoutput-filter functions in the context of the eshell
    ;; buffer. This breaks the xterm color filtering when the eshell buffer is updated
    ;; when it's not currently focused.
    ;; To remove if/when fixed upstream.
    (defun eshell-output-filter@spacemacs-with-buffer (fn process string)
      (let ((proc-buf (if process (process-buffer process)
                        (current-buffer))))
        (when proc-buf
          (with-current-buffer proc-buf
            (funcall fn process string)))))
    (advice-add
     #'eshell-output-filter
     :around
     #'eshell-output-filter@spacemacs-with-buffer)

    ;; Visual commands
    ;; At the moment, eshell is stream-based in its interactive input and
    ;; output.  This means that full-screen commands, such as "vi" or
    ;; "lynx", will not display correctly.  These are therefore thought of
    ;; as "visual" programs.  In order to run these programs under Emacs,
    ;; Eshell uses the term.el package, and invokes them in a separate
    ;; buffer, giving the illusion that Eshell itself is allowing these
    ;; visual processes to execute.
    (mapc (lambda (x) (add-to-list 'eshell-visual-commands x))
          '("htop" "less" "tmux" "top", "ssh"))
    (setq eshell-destroy-buffer-when-process-dies t)

    ;; automatically truncate buffer after output
    (when (boundp 'eshell-output-filter-functions)
      (add-hook 'eshell-output-filter-functions #'eshell-truncate-buffer))
    )
  )

(use-package eshell-prompt-extras
  :defer t
  :commands epe-theme-lambda
  :init
  (progn
    (setq eshell-highlight-prompt nil
          eshell-prompt-function 'epe-theme-lambda)))

(use-package xterm-color
  :defer t
  :init
  (progn
    ;; Comint and Shell
    (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter)
    (setq comint-output-filter-functions
          (remove 'ansi-color-process-output comint-output-filter-functions))

    (defun *sys/init-eshell-xterm-color* ()
      "Initialize xterm coloring for eshell"
      (setq-local xterm-color-preserve-properties t)
      (make-local-variable 'eshell-preoutput-filter-functions)
      (add-hook 'eshell-preoutput-filter-functions 'xterm-color-filter)
      (setq-local eshell-output-filter-functions
                  (remove 'eshell-handle-ansi-color
                          eshell-output-filter-functions)))

    (add-hook 'eshell-mode-hook '*sys/init-eshell-xterm-color*)))

;; TODO style aweshell
(use-package aweshell
  :defer t
  :straight
  :config
  (progn
    (setq eshell-prompt-function 'epe-theme-lambda))
  (aweshell
   :type git
   :host github
   :files (:defaults "aweshell")
   :repo "manateelazycat/aweshell"))
Clone this wiki locally