How can I run Cygwin Bash Shell from within Emacs?

后端 未结 8 1629
温柔的废话
温柔的废话 2020-12-01 01:34

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 a

相关标签:
8条回答
  • 2020-12-01 02:10

    The best solution I've found to this is the following:

    ;; When running in Windows, we want to use an alternate shell so we
    ;; can be more unixy.
    (setq shell-file-name "C:/MinGW/msys/1.0/bin/bash")
    (setq explicit-shell-file-name shell-file-name)
    (setenv "PATH"
        (concat ".:/usr/local/bin:/mingw/bin:/bin:"
            (replace-regexp-in-string " " "\\\\ "
                (replace-regexp-in-string "\\\\" "/"
                    (replace-regexp-in-string "\\([A-Za-z]\\):" "/\\1"
                        (getenv "PATH"))))))
    

    The problem with passing "--login" as cjm suggests is your shell will always start in your home directory. But if you're editing a file and you hit "M-x shell", you want your shell in that file's directory. Furthermore, I've tested this setup with "M-x grep" and "M-x compile". I'm suspicious that other examples here wouldn't work with those due to directory and PATH problems.

    This elisp snippet belongs in your ~/.emacs file. If you want to use Cygwin instead of MinGW, change the first string to C:/cygwin/bin/bash. The second string is prepended to your Windows PATH (after converting that PATH to an appropriately unixy form); in Cygwin you probably want "~/bin:/usr/local/bin:/usr/bin:" or something similar.

    0 讨论(0)
  • 2020-12-01 02:10

    I'm using EmacsW32. C-h a shell$ gives a list of shell launching commands and the commands cmd-shell and cygwin-shell look interesting. Both commands need EmacsW32. They are also found in the menu: Tools > W&32 Shells.

    If you run cygwin-shell for the first time, and if you have not setup cygwin path in Emacs, it leads you to the Customization page where you can setup the cygwin path by pressing Find button.

    0 讨论(0)
提交回复
热议问题