How can I run Cygwin Bash Shell from within Emacs?

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.

Leave a Comment