How can I run Cygwin Bash Shell from within Emacs?

Ray picture Ray · Oct 24, 2008 · Viewed 20.6k times · Source

I am running GNU Emacs on Windows so entering:

M-x shell

launches the Windows command-line DOS shell. However, I would like to instead be able to run the Cygwin Bash Shell (or any other non-Windows shell) from within Emacs. How can this be easily done?

Answer

cjm picture cjm · Oct 24, 2008

shell-file-name is the variable that controls which shell Emacs uses when it wants to run a shell command.

explicit-shell-file-name is the variable that controls which shell M-x shell starts up.

Ken's answer changes both of those, which you may or may not want.

You can also have a function that starts a different shell by temporarily changing explicit-shell-file-name:

(defun cygwin-shell ()
  "Run cygwin bash in shell mode."
  (interactive)
  (let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
    (call-interactively 'shell)))

You will probably also want to pass the --login argument to bash, because you're starting a new Cygwin session. You can do that by setting explicit-bash-args. (Note that M-x shell uses explicit-PROGRAM-args, where PROGRAM is the filename part of the shell's pathname. This is why you should not include the .exe when setting the shell.