On W32 Emacs why does Ctrl-D in Cygwin or MinGW bash issues repeated EOFs? - shell

I'm using W32 GNU Emacs 24.1.50.1 with Cygwin bash 3.2.51. I know that this combination is very troublesome (see EmacsWiki and Cygwin list). However the problem I want to solve now is not confined to Cygwin. I got the issue with MinGW as well. So, the problem is:
In Emacs start a shell via M-x shell provided you have set up the variables shell-file-name and explicit-bash-args appropriately (see e.g. here). Then issue a command which expects stdin input, e.g. cat. To cancel out of cat you can usually type Ctrl-D once and you return to the shell prompt. In W32 emacs when you do this (or even when you issue explicitly M-x comint-send-eof) the cat command gets exited and the bash shell quits as well.
I tried to increases bash's "resilience' by setting the environment variable IGNOREEOF to, say, 5, but then a single Ctrl-D results in the following output
$ Use "exit" to leave the shell.
$ Use "exit" to leave the shell.
$ Use "exit" to leave the shell.
$ Use "exit" to leave the shell.
$ Use "exit" to leave the shell.
$ exit
Process shell finished
and, of course, the bash has exited again. This problem only happens when the shell runs in W32 emacs - Cygwin bash through the Cygwin tty window and MinGW bash through its own MinTTY work fine.
Why is this happening in W32 Emacs and how can I just exit the running subcommand (e.g. cat) when using W32 Emacs without exiting the bash shell?

The notion of tty like you expect it to behave doesn't really exist in the W32 worl. If you want to see this Unixy behavior, you need not only to run a Cygwin program but that Cygwin program needs to talk to another Cygwin program (Emacs, terminal, you name it). IOW you'll only get that with the Cygwin version of Emacs.

The GNU Emacs FAQ for MS Windows notes that this issue exists for any sub-process in the shell buffer. So it affects the DOS command line as well (but of course you don't usually use Ctrl-D in DOS, so it's not so noticeable). No workaround is suggested in the FAQ, so I'm guessing that there's no easy fix.

Usually you can use Ctrl-Z as well as Ctrl-D. Take a look at this note:
http://ignaciopp.wordpress.com/2009/07/02/emacs-shell-workaround-for-killing-input-in-windows-version/

Related

How can I run Windows 10's bash for Emacs mingw32 for Windows?

I would like to use the recent bash shell of Windows 10 in shell mode of Emacs (mingw32) for Windows. Could anyone advise how could I do that?
You can use one of the other terminal mode: term or ansi-term by typing M-x term or M-x ansi-term.
When being invoked, these terminals will ask for the path to your shell. Here you just need to put the correct path to the Windows shell.

Difference between Bash shell and Bash terminal?

Ok, I hope this question makes some sense but what is the difference between a bash shell and a bash terminal? Example. When I first open up terminal I have a prompt with my current dir and my user name. In the terminal window header it says -bash- , when I type echo $SHELL I get bash. So by default the shell is bash. Where my confusion comes into play is when I type bash. My prompt then goes to bash-3.2$.Obviously it's a different mode. Are ther any major differences? I have read the man page with no answer. I understand what a bash shell is but just do not get the difference. Thanks for the clarity in advance.
There is no difference, they are both instances of the bash shell.
The reason you are seeing a different prompt is that your initial login shell sources ~/.bash_profile where presumably you have your prompt set. When you type bash it invokes another shell but because this one isn't a login shell, it doesn't source ~/.bash_profile and so you get the default prompt.
If you were call bash -l, (which invokes bash as if it were a login shell) I bet you would see that your original prompt remains

Shell commands from vim

What is the best approach of using shell commands from vim? I know about the possibility of !shell_command. But this doesn't know all commands e.g.
export OSTYPE; make install So I have to run it outside vim. Is there better approach?
I know this is a bit late, but my preferred approach is suspending the vim process (Ctrl+z). You return to your shell/bash command prompt.
Then execute whatever command(s) you like.
Return to vim by typing fg
You can start a shell from Vim using the :sh command. When the shell exits
(after the exit command or Ctrl+D) you return to Vim. The name for the shell command comes from the shell option.
For terminal Vim (on unix-like systems) you can also use Ctrl+Z to suspend Vim and get back to the shell from which it was run. To resume the Vim process, use the fg command.

cygwin shell in emacs /cmd.exe in windows

I am attempting to get python to run in a command shell in emacs. I have tried the standard M-x shell that comes with windows emacs and then type 'python' but python just hangs up (no output). I have also tried running other program shells such as bash.exe from cygwin with the same result. Any way to get a shell that can run other programs like python?
Why not use M-x python-shell? This provides an interactive REPL for Python within Emacs.

Need to write a program to sanely configure a login shell

I just started using a Solaris 10 (Sparc) box where I telnet in and get confronted with a very unfriendly interface (compared to the standard bash shell I use in cygwin or linux) --- the arrow keys do not work as I expect them to. Being an NIS system, changing the shell is not as easy as using the "chsh" command. And setting the SHELL environment variable in ~/.login and ~/.profile is not working for me. So I'm thinking that I may need to write a script to determine if bash is running the script and starting bash if the answer is no. My first attempt, trying to invoke /bin/bash from ~/.profile seems to work but kind of doesn't feel right. Other suggestions? And how do I tell programmatically which shell is actually executing?
You can tell what shell is running with echo $0. For example:
$ echo $0
-bash
If you're changing shell you probably want to replace the current shell process rather than be a child of it, so use exec.
Also, you want to pass bash the -l flag so it acts as if it has been called as part of the login process.
So you'll want something like:
exec bash -l
You are probably running with ksh(1) on Solaris. You have several options, read the manpage for ksh and configure it or install another shell you're more familiar with like bash. I'd personnaly recommend zsh.

Resources