Search code examples
emacscygwin

I want to run the cygwin bash shell from native windows emacs app


I have followed instructions from How can I run Cygwin Bash Shell from within Emacs? this question and I have gone further and added the (setq explicit-bash-args '("--login" "-i")) command, however emacs continues to only display the dos prompt when I type M-x shell. In summery my .emacs file looks like this:

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

Please be gentle with the answers as I am right at the bottom of the famous vertical emacs learning curve!


Solution

  • If you implemented the answer from that question, note that you have to do M-x cygwin-shell to start bash. If you want to use it for every M-x shell you need to call

    (setq explicit-shell-file-name "C:/cygwin/bin/bash")
    

    Since you stated that you are learning, here's a few tips when trying this out.

    • type C-x C-f ~/.emacs to open your .emacs file in your user path.
    • Enter your function above at the end
    • M-x load-file [RET] .emacs: loads the buffer (no need to restart emacs)
    • C-h a: If you are interested in some specific action, you can look it up
    • C-h v [RET] variable: can inspect the variable, check the value of explicit-bash-args for instance

    And, btw, I'm not sure what the "--login -i" does, but someone stated in a comment that you should have that so "ls" would work. If you have your cygwin bin path in your PATH environment variable, bash will find ls anyway. No need to escape the path variable either, this is handled by bash (do an echo $PATH in bash when you get it working and you'll see).