【问题标题】:cygwin bash does not display correctly in emacs shellcygwin bash 在 emacs shell 中无法正确显示
【发布时间】:2012-03-12 15:44:58
【问题描述】:

我正在用 emacs 尝试 cygwin。 我的环境是Windows 7 x64,emacs-24.0.93.1,cygwin 2.769,系统编码是gbk,cygwin的编码系统默认是utf-8,emacs的编码系统默认是gbk

我使用setup-cygwin 用emacs设置cygwin。 我可以使用 cygwin bash 启动 emacs shell。但是我遇到了两个问题。 一、bash开头的两个警告

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

其次,bash响应后,出现了一些奇怪的字符。

有人知道发生了什么吗?

【问题讨论】:

    标签: bash emacs cygwin


    【解决方案1】:

    【讨论】:

    • 我可以确认 Emacs 23.2.1 也存在这个问题,而不仅仅是 23.4.1。真正的解决方法是升级 Cygwin,而是坚持使用旧版本。这就引出了一个问题:为什么这个问题被标记为 “NTEmacs 破坏 cygwin bash”? (即应该是“cygwin bash break NTEmacs”)。
    • Cygwin 2.8.1 和 Emacs 24.5.1 仍然存在问题。答案中的 Gmane 链接不起作用。我认为这是邮件列表消息:sourceware.org/ml/cygwin/2012-03/msg00347.html.
    【解决方案2】:

    将此添加到您的初始化中:

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

    至于你的其他信息,我最近才开始自己收到。我已经运行 emacs/cygwin/bash 一段时间了,但我还不确定是什么原因造成的。

    【讨论】:

    • 嘿,伙计,这对我不起作用...无论如何,谢谢您的提示
    • @MartinLuo,为了确定,你当然需要重启 emacs。
    • 是的,我确实重新启动了它,但它仍然是相同的方式
    【解决方案3】:

    如果没有其他方法,您可以使用以下功能为运行 M-x shell 的情况自定义 shell 提示:

    M-: (info "(emacs) Interactive Shell") RET

    Emacs 向新的 shell 发送文件的内容 ~/.emacs_SHELLNAME' as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is~/.emacs_bash'。如果这个文件不是 找到后,Emacs 尝试使用 `~/.emacs.d/init_SHELLNAME.sh'。

    因此您可以在该文件中指定不带颜色代码的提示(即设置PS1 环境变量)。

    【讨论】:

      【解决方案4】:

      关于奇怪的字符,我意识到我把这段代码弄乱了:

           ; Always prefer UTF-8 encoding
           ;(prefer-coding-system 'utf-8-with-signature-dos)
      

      这导致大多数命令失败,因为它将 BOM () 添加到命令调用中:

           ----------------------------------------------------------
           -*- mode: grep; default-directory: "~/" -*-
           Grep started at Sat Oct 06 02:53:32
           grep -nH -e test
           'grep' is not recognized as an internal or external command,
           operable program or batch file.
      

      【讨论】:

        【解决方案5】:

        strace -o bash.log bash 启动一个新的终端(bash)可以帮助调试这个问题。 看起来是 bash 尝试打开的某些设备缺少适当的权限或者甚至不存在。

        grep bash.log 文件中的任何 /dev 字符串,并检查那里是否有任何问题。 例如我的 bash 打开 /dev/tty:

        $ grep "/dev" bash.log
        open("/dev/tty", O_RDWR|O_NONBLOCK)     = 3
        

        【讨论】:

        • 不知道您的建议是否会帮助我解决问题,但由于您是我打开赏金后唯一回答此问题的人,所以您明白了。 :) 我会在有机会实施您的解决方案时立即报告。
        • 我不知道这个答案是否对我有帮助。但是我会在以后使用 Windows 时尝试一下,我大部分时间都使用 Mac。 :) 感谢您的回答!
        【解决方案6】:

        您看到的是 Emacs 在您的 PS1 变量中的一些控制代码上阻塞。这就是为什么您总是在提示打印之前看到该垃圾。

        解决方法

        将此添加到您的 .bashrc 中,以便在您从 Emacs 中运行 shell 时给自己一个愚蠢的提示:

        if [ "$EMACS" == "t" ]; then
            PS1='\u \w>'
        fi
        

        此解决方案基于: http://cygwin.com/ml/cygwin/2006-06/msg00491.html

        我只是在使用更简单的 PS1。

        【讨论】:

          【解决方案7】:

          刚刚遇到并通过为我的 64 位 Win7(以前是 32 位)安装 64 位 cygwin 解决了这个问题。根据您的 Windows 版本选择正确的Cygwin setup

          如何分辨您的 Windows 版本:"Start" > right-click "Computer" [right side of Start pane] > "Properties" [context menu],在窗口的一半左右寻找“系统类型”。

          在 cygwin 设置过程中,确保选择 emacs 包 - 我选择了“常规”emacsemacs-x11emacs-w32(本机编译为 Windows)。据我所知,emacs-w32 看起来/感觉就像常规的 Windows emacs 二进制文件。

          几点说明:

          • 64位cygwin默认安装在c:\cygwin64(可能需要更新PATH
          • emacs-w32 中的路径是使用 unix 样式路径名(“/bin/bash”)指定的
          • 默认情况下 emacs-w32 似乎使用 sh 作为外壳 - 您可以通过设置 explicit-shell-file-name.emacs 中更改它: (setq explicit-shell-file-name "/bin/bash")
          • 如果您看到有趣的控制字符(例如 ^G 等),您可能想在 .bash_profile 中更改您的 PS1
          • 您可能需要明确创建您的主目录才能更改 ~/.bash_profilemkdir /home/<username>

          希望这会有所帮助。

          【讨论】:

            猜你喜欢
            • 2010-09-19
            • 1970-01-01
            • 1970-01-01
            • 2010-10-08
            • 2021-02-15
            • 2013-05-12
            • 2011-07-02
            • 2012-04-25
            相关资源
            最近更新 更多