【问题标题】:How do I get Emacs shell mode to either render (or ignore) my colors instead of printing ASCII codes?如何让 Emacs shell 模式渲染(或忽略)我的颜色而不是打印 ASCII 代码?
【发布时间】:2008-11-01 23:44:15
【问题描述】:

问题的症状看起来像“[0m[27m[24m[J[34;1””,在终端上转换为蓝色。

-A

【问题讨论】:

  • 关于我的配置的更多信息:zsh + GNU emacs

标签: emacs colors ascii


【解决方案1】:

我的.emacs 中有以下内容

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

【讨论】:

  • 在最新版本的 Emacs 中不需要自动加载(默认自动加载)。
  • 这确实有帮助,(出现蓝色)但是缓冲区中仍然出现了一些 ASCII 控制代码。毫无疑问,有一个或多个细节可以与此解决方案相结合。
  • 我认为这个答案得到了支持,这反映了它正在为 stackoverflow 用户提供一些通用平台。但另请参阅接受的答案。
  • 目前为止在 bash 中为我工作。
【解决方案2】:

目前给我一些成功的解决方案是将 shell 函数重新定义为 ansi 术语:

;; shell-mode
(defun sh ()
  (interactive)
  (ansi-term "/bin/zsh"))

【讨论】:

  • 这是个好主意。它还解决了 shell-mode 与 more/less 和 man 等命令的不兼容问题。
  • 隐藏“真实”的 shell 命令。直接使用 term 或 ansi-term 而不是隐藏普通 shell 模式。
【解决方案3】:

对于“忽略”选项,请在您的 ~/.emacs_{bash,tsch,whatever-your-shell-is-called} 文件中添加类似“alias ls=ls”或“unset LS_COLORS”的内容。该文件在由 emacs 创建的所有从属 shell 中执行。

Emacs 向新 shell 发送文件 ~/.emacs_shellname 的内容作为输入(如果存在),其中 shellname 是从中加载 shell 的文件的名称。例如,如果您使用 bash,则发送给它的文件是~/.emacs_bash。如果没有找到这个文件,Emacs 会尝试回退到~/.emacs.d/init_shellname.sh

【讨论】:

    【解决方案4】:

    以下内容应该可以在您的 .bash_profile 或 .bashrc 中使用

    case $TERM in
    xterm-color)
    export PS1='\[\e]0;\W\007\]\[\e[34;1m\]\W\[\e[0m\]\$ '
    ;;
    *)
    export PS1='\W\$ '
    ;;
    esac
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多