Windows, Emacs, Git Bash, and the Shell

Windows 7. Emacs 24.3.1. Git 1.8.1.msysgit. 1. In my equivalent .emacs file, I have the following:

(if (equal system-type 'windows-nt) (progn (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/sh.exe") (setq shell-file-name "bash") (setq explicit-sh.exe-args '("--login" "-i")) (setenv "SHELL" shell-file-name) (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m))) 

This works fine when I want to make an Mx shell: I can open the shell and type “ls”.

However, the Mx shell-command fails. When I try to run "ls" with a shell command (which should print its output in the * Shell command line buffer, according to the command Ch f shell-command), I get one error message:

"Search program: permission denied, bash"

There are some very old suggestions about Google about calling and many questions about StackOverflow about how to make the shell work in Emacs. Note that the Mx shell works fine, and I would like to work with shell commands.

(Reason: https://github.com/donkirkby/live-py-plugin#installing-the-emacs-mode )

+6
source share
2 answers

Try specifying both variables to indicate the same executable and make sure the path is in exec-path :

 (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/bash.exe") (setq shell-file-name explicit-shell-file-name) (add-to-list 'exec-path "C:/Program Files (x86)/Git/bin") 
+11
source

I know this is an old question, but I found it when I was looking for help on the same problem, so here is the solution that I use for my specific use case, in case it helps someone in the future.

I sync my .emacs.d between all the computers I use emacs on, including Linux and Windows. I pasted this into my init.el file to automatically fix this problem on a Windows environment:

 ;; Set Windows-specific preferences if running in a Windows environment. (defun udf-windows-setup () (interactive) ;; The variable `git-shell-path' contains the path to the `Git\bin' ;; file on my system. I install this in ;; `%USERPROFILE%\LocalAppInfo\apps\Git\bin'. (setq git-shell-path (concat (getenv "USERPROFILE") "\\LocalAppInfo\\apps\\Git\\bin")) (setq git-shell-executable (concat git-shell-path "\\bash.exe")) (add-to-list 'exec-path git-shell-path) (setenv "PATH" (concat git-shell-path ";" (getenv "PATH"))) (message "Windows preferences set.")) (if (eq system-type 'windows-nt) (udf-windows-setup)) 

Note that the git-shell-path variable must be defined based on where git installed on your system. I install it in %USERPROFILE%\LocalAppInfo\apps\Git on the same Windows machine where I use it.

+1
source

Source: https://habr.com/ru/post/945515/


All Articles