首页 > 解决方案 > 外壳和颜色输出

问题描述

在使用 eshell 时,我面临一个关于 shell 输出颜色实现的奇怪行为。这是我的 .emacs 的内容:

(require 'xterm-color)
(require 'eshell)
(add-hook 'eshell-before-prompt-hook
          (lambda ()
            (setq xterm-color-preserve-properties t)))

(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
(setq eshell-output-filter-functions (remove 'eshell-handle-ansi-color eshell-output-filter-functions))
(setenv "TERM" "xterm-256color")

奇怪的是,在 emacs 初始化后,eshell 无法正确显示输出(例如 git 或 pytest)的颜色。但是它不会引发任何错误,并且在它被初始化之后,我使用 Cx Ce 评估我的 init 文件的这一部分,并且在我这样做并重新启动 eshell 之后,它可以按预期正常工作。

我不明白为什么只有在初始化 emacs 之后执行它才会起作用,但不会对 .emacs 产生预期的影响。

我的 .emacs 上确实有 (setq initial-buffer-choice 'eshell) 行,但仅在上述部分之后。

关于为什么会发生这种情况的任何见解都会有所帮助。谢谢,

编辑 1

我将问题缩小到setenv语句和initial-buffer-choice. 出于某种原因,当我没有initial-buffer-choice注释时,TERM变量设置为dumb. 另一方面,如果我initial-buffer-choice在启动后评论并打开 eshell,那么一切都按预期工作。

我尝试将setenv执行添加为 eshell-mode 和 emacs-startup 的钩子,以查看是否可以在启动期间强制执行它,但没有任何效果。

标签: colorsemacseshell

解决方案


推荐阅读