[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell-command in Windows 7

From: John Mastro
Subject: Re: shell-command in Windows 7
Date: Sat, 15 Apr 2017 13:08:28 -0700

John Mastro <> wrote:
> 42 147 <> wrote:
>> setup-cygwin.el is perfectly compatible with the code that John Mastro
>> suggested (which works better than what I had previously anyway). I need
>> setup-cygwin.el to run cygwin in Emacs. No way I'll stop loading it!
> I've been using native Windows builds of Emacs together with Cygwin for
> several years now. (Eli recommends against it for very sensible reasons,
> but I haven't found anything better and it works well enough for me).
> During that time, I've never used setup-cygwin.el. I don't even know
> what it does, so I could be missing out, but I wanted to mention that
> (at least in my use case) setup-cygwin.el isn't necessary to use Cygwin
> with Emacs.

I should mention that I do have some home-grown Cygwin-related settings

I do not claim this is the best or right way to do it, but it's what I
ended up with over time, so I'll share it FWIW.

(defvar cygwin-path-directories
  '("/bin" "/usr/bin" "/usr/local/bin"
    "/Windows" "/ProgramData/Oracle/Java/javapath"))

(defun cygwinize-file-name (name)
  (if (string-match "\\`\\([A-Za-z]\\):\\(/\\|\\\\\\)" name)
      (let* ((drive (match-string 1 name))
             (sep   (match-string 2 name))
             (more  (substring name (match-end 2))))
        (concat (if (member drive '("c" "C")) "" (concat "/" drive))
                (if (equal sep "\\")
                    (replace-regexp-in-string "\\\\" "/" more)

(defun init-for-cygwin ()
  (let* ((home (cygwinize-file-name (or (getenv "HOME")
                                        (error "HOME not defined"))))
         (home/bin (concat home
                           (unless (string-suffix-p "/" home) "/")
         (path (cons home/bin cygwin-path-directories)))
    (setenv "PATH" (mapconcat #'identity path ":"))
    (setq exec-path (mapcar (lambda (dir) (concat "c:" dir)) path))
    (let ((shell (or (executable-find "zsh")
                     (executable-find "bash")
                     (error "Can't find zsh or bash"))))
      (setq shell-file-name shell)
      (setq explicit-shell-file-name shell)
      (setq ediff-shell shell)
      (setq null-device "/dev/null")
      (setenv "SHELL" shell))))

(when (and (eq system-type 'windows-nt)
           (file-executable-p "c:/bin/bash.exe"))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]