jiluo
jiluo

Reputation: 2346

cygwin bash does not display correctly in emacs shell

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

I use setup-cygwin to 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

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. enter image description here

Does anyone know what happened?

Upvotes: 25

Views: 6862

Answers (7)

23emacs
23emacs

Reputation: 113

A "known problem," with no known solution (yet):

https://www.emacswiki.org/emacs/NTEmacsWithCygwin#toc2

https://sourceware.org/ml/cygwin/2012-03/msg00347.html

Upvotes: 11

Johnster
Johnster

Reputation: 152

Just encountered and solved this problem by installing 64-bit cygwin for my 64-bit Win7 (previously had 32-bit). Pick the right Cygwin setup according to your Windows version.

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.

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-w32 looks/feels just like the regular Windows emacs binary as far as I can tell.

A few notes:

  • 64-bit cygwin install in c:\cygwin64 by default (may need to update PATH)
  • Paths in emacs-w32 are specified using unix style pathnames ("/bin/bash")
  • By default emacs-w32 seems to use sh as the shell - you can change that in .emacs by setting explicit-shell-file-name: (setq explicit-shell-file-name "/bin/bash")
  • If you see funny control character (eg ^G and such) you probably want to change your PS1 in .bash_profile
  • You may need to explicitly create your home dir before you can change ~/.bash_profile: mkdir /home/<username>

Hope this helps.

Upvotes: 0

btello
btello

Reputation: 51

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.

Workaround:

Add this to your .bashrc to give yourself a dumbed down prompt when you're running a shell from within Emacs:

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

This solution is based on: http://cygwin.com/ml/cygwin/2006-06/msg00491.html

I'm just using a much simpler PS1.

Upvotes: 0

Arnestig
Arnestig

Reputation: 2342

start a new terminal (bash) with strace -o bash.log bash could 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.

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 "/dev" bash.log
open("/dev/tty", O_RDWR|O_NONBLOCK)     = 3

Upvotes: 0

numdig
numdig

Reputation: 121

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:

     ----------------------------------------------------------
     -*- 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.

Upvotes: 0

phils
phils

Reputation: 73236

If nothing else works, you can customise your shell prompt for the case when you are running M-x shell by making use of the following functionality:

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'.

So you can specify a prompt without colour codes in that file (i.e. set the PS1 environment variable).

Upvotes: 1

harpo
harpo

Reputation: 43158

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.

Upvotes: 1

Related Questions