【问题标题】:Windows, Emacs, Git Bash, and shell-commandWindows、Emacs、Git Bash 和 shell 命令
【发布时间】:2013-05-16 14:50:33
【问题描述】:

Windows 7. Emacs 24.3.1。 Git 1.8.1.msysgit.1。我的等效 .emacs 文件中有以下内容:

(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)))

这在我想做 M-x shell 时非常有用:我可以弹出一个 shell 并输入“ls”。

但是,M-x shell-command 失败了。当我尝试通过 shell-command 运行“ls”时(根据 Ch f shell-command,它应该在 *Shell Command Output* 缓冲区中打印其输出),我收到一条错误消息:

“搜索程序:权限被拒绝,bash”

Google 上有一些关于 call-process 的非常古老的建议,StackOverflow 上有很多关于让 shell 在 Emacs 中工作的问题。请注意 M-x shell 效果很好,而我想要使用的是 shell-command。

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

【问题讨论】:

    标签: windows shell emacs


    【解决方案1】:

    使用 GitBash,您可以使用 lein 脚本代替 lein.bat 脚本。将 lein 脚本放入 Windows 用户帐户中名为 bin 的目录中。 GitBash 应该在其可执行文件PATH 上有那个bin 目录,所以你可以在任何地方运行lein。

    使用这种方法,您不需要在 Emacs Lisp 中进行任何配置。

    See my full answer

    【讨论】:

      【解决方案2】:

      我知道这是一个较老的问题,但我在寻找同一问题的帮助时发现了它,所以这是我用于特定用例的解决方案,以防将来对某人有所帮助。

      我在我使用 emacs 的所有计算机(包括 Linux 和 Windows 计算机)之间同步了我的 .emacs.d。我将它插入到我的init.el 文件中,以便在 Windows 环境中适当地自动处理此问题:

      ;; 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))
      

      请注意,变量git-shell-path 需要根据您在系统上安装git 的位置来定义。我将它安装在我使用它的一台 Windows 机器上的 %USERPROFILE%\LocalAppInfo\apps\Git 中。

      【讨论】:

        【解决方案3】:

        尝试将两个变量都设置为指向同一个可执行文件,并确保路径位于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")
        

        【讨论】:

        • 在此之间并将“C:/Program Files (x86)/Git/bin”添加到 Windows 路径中,shell-command 现在可以工作了。谢谢!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-10-14
        • 1970-01-01
        • 1970-01-01
        • 2015-06-18
        • 2016-08-16
        • 1970-01-01
        • 2016-08-26
        相关资源
        最近更新 更多