cygwin bash 在 emacs shell 中无法正确显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9670209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cygwin bash does not display correctly in emacs shell
提问by jiluo
I'm trying cygwin with emacs. My environment is Windows 7 x64, emacs-24.0.93.1, cygwin 2.769, system encoding is gbk, cygwin's coding system is default to utf-8, and emacs's coding system is default to gbk
我正在用 emacs 尝试 cygwin。我的环境是windows 7 x64,emacs-24.0.93.1,cygwin 2.769,系统编码是gbk,cygwin的编码系统默认是utf-8,emacs的编码系统默认是gbk
I use setup-cygwinto setup cygwin with emacs. And I can launch emacs shell using cygwin bash.But I encountered two problem. First, two warnings at the beginning of bash
我使用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
Second, after bash response, some strange characters appeared.

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

Does anyone know what happened?
有谁知道发生了什么?
回答by 23emacs
A "known problem," with no known solution (yet):
一个“已知问题”,没有已知的解决方案(还):
http://emacswiki.org/emacs/NTEmacsWithCygwin
http://emacswiki.org/emacs/NTEmacsWithCygwin
回答by phils
If nothing else works, you can customise your shell prompt for the case when you are running M-x shellby making use of the following functionality:
如果没有其他效果,您可以M-x shell通过使用以下功能在运行时为案例自定义 shell 提示:
M-:(info "(emacs) Interactive Shell")RET
M-:(info "(emacs) Interactive Shell")RET
Emacs sends the new shell the contents of the file
~/.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'. If this file is not found, Emacs tries with `~/.emacs.d/init_SHELLNAME.sh'.
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'。
So you can specify a prompt without colour codes in that file (i.e. set the PS1environment variable).
因此,您可以在该文件中指定不带颜色代码的提示(即设置PS1环境变量)。
回答by harpo
Add this to your init:
将此添加到您的初始化:
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
As for your other message, I've started getting that myself only recently. I've run emacs/cygwin/bash for a while, and I'm not sure yet what caused it.
至于你的另一条消息,我自己最近才开始收到。我已经运行 emacs/cygwin/bash 一段时间了,但我不确定是什么原因造成的。
回答by numdig
Regarding the strange characters, I realised that I had this piece of code messing around:
关于奇怪的字符,我意识到我有这段代码乱七八糟:
; Always prefer UTF-8 encoding
;(prefer-coding-system 'utf-8-with-signature-dos)
And this was causing most commands to fail, because it was adding the BOM (???) to the command invokation:
这导致大多数命令失败,因为它将 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.
回答by Arnestig
start a new terminal (bash) with strace -o bash.log bashcould help debugging this problem.
What it looks like is that some device that bash tries to open is missing appropriate permissions or doesn't even exist.
启动一个新的终端 (bash)strace -o bash.log bash可以帮助调试这个问题。看起来 bash 尝试打开的某些设备缺少适当的权限或什至不存在。
grep your bash.log file for any /dev strings and check if there is any issues there. For example my bash opens up /dev/tty:
grep bash.log 文件中的任何 /dev 字符串并检查那里是否有任何问题。例如,我的 bash 打开 /dev/tty:
$ grep "/dev" bash.log
open("/dev/tty", O_RDWR|O_NONBLOCK) = 3
回答by btello
What you're seeing is Emacs choking on some control codes in your PS1 variable. That's why you consistently see that junk just before your prompt gets printed.
您所看到的是 Emacs 因 PS1 变量中的某些控制代码而窒息。这就是为什么你总是在你的提示被打印之前看到那些垃圾。
Workaround:
解决方法:
Add this to your .bashrc to give yourself a dumbed down prompt when you're running a shell from within Emacs:
将此添加到您的 .bashrc 中,以便在您从 Emacs 中运行 shell 时给自己一个简化的提示:
if [ "$EMACS" == "t" ]; then
PS1='\u \w>'
fi
This solution is based on: http://cygwin.com/ml/cygwin/2006-06/msg00491.html
该解决方案基于:http: //cygwin.com/ml/cygwin/2006-06/msg00491.html
I'm just using a much simpler PS1.
我只是使用更简单的 PS1。
回答by Johnster
Just encountered and solved this problem by installing 64-bit cygwinfor my 64-bit Win7 (previously had 32-bit). Pick the right Cygwin setupaccording to your Windows version.
刚刚通过为我的 64 位 Win7(以前有 32 位)安装64 位 cygwin遇到并解决了这个问题。根据您的 Windows 版本选择正确的Cygwin 设置。
How to tell your Windows version: "Start" > right-click "Computer" [right side of Start pane] > "Properties" [context menu], look for "System type" about halfway down the window.
如何判断您的 Windows 版本:"Start" > right-click "Computer" [right side of Start pane] > "Properties" [context menu]在窗口的中间位置寻找“系统类型”。
During the cygwin setup process, make sure to choose the emacs packages - I picked "regular" emacs, emacs-x11, and emacs-w32(native compiled for windows). The emacs-w32looks/feels just like the regular Windows emacs binary as far as I can tell.
在 cygwin 设置过程中,确保选择 emacs 包 - 我选择了“常规” emacs、emacs-x11和emacs-w32(为 Windows 本地编译)。据我所知,emacs-w32 的外观/感觉就像常规的 Windows emacs 二进制文件。
A few notes:
一些注意事项:
- 64-bit cygwin install in c:\cygwin64by default (may need to update PATH)
- Paths in emacs-w32are specified using unix style pathnames ("/bin/bash")
- By default emacs-w32seems to use shas the shell - you can change that in .emacsby setting
explicit-shell-file-name:(setq explicit-shell-file-name "/bin/bash") - If you see funny control character (eg
^Gand such) you probably want to change your PS1in .bash_profile - You may need to explicitly create your home dir before you can change ~/.bash_profile:
mkdir /home/<username>
- 64 位 cygwin默认安装在c:\cygwin64(可能需要更新PATH)
- 在路径的emacs-W32使用UNIX风格的路径名指定(“/斌/庆典”)
- 默认情况下,emacs-w32似乎使用sh作为外壳 - 您可以通过设置在.emacs 中更改它
explicit-shell-file-name:(setq explicit-shell-file-name "/bin/bash") - 如果您看到有趣的控制字符(例如
^G等等),您可能想在.bash_profile 中更改您的PS1 - 在更改~/.bash_profile之前,您可能需要明确创建主目录:
mkdir /home/<username>
Hope this helps.
希望这可以帮助。

