如何git gui从特定目录执行shell命令(例如)?我更喜欢跨平台的方法,它不依赖shell操作符,&&或者;因为我需要在Windows和unix上运行它.(例如,调用cd /path/to/dir && git gui在Windows上&&无效,因为无效.)
我试过了:
(async-shell-command (concat "cd \""
(replace-regexp-in-string
"/" "\\\\" (file-name-directory (buffer-file-name))) "\" ; git gui"))
Run Code Online (Sandbox Code Playgroud)
这失败了,因为无论出于何种原因,shell认为; git gui是路径的一部分,它报告:The system cannot find the path specified.
所以,我宁愿不处理shell怪癖,我希望有一个elisp函数设置目录为shell-command或async-shell-command.我试过了:
(shell-process-pushd (file-name-directory (buffer-file-name)))
(shell-command "git gui")
(shell-process-popd nil)
Run Code Online (Sandbox Code Playgroud)
这没有任何效果:git gui总是在我的主目录中打开.(另外,shell-process-pushd/popd没有记录.)
这也行不通:
(start-process "gitgui" nil "git" "gui")
Run Code Online (Sandbox Code Playgroud)
这也不是:
(let '(bufdir (file-name-directory (buffer-file-name)))
(with-temp-buffer
(print bufdir)
(cd bufdir)
(shell-command "git gui")))
Run Code Online (Sandbox Code Playgroud)
您确定在emacs-lisp中使用尾部斜杠表示目录名吗?
(let ((default-directory "~/.emacs.d"))
(shell-command-to-string "echo $PWD"))
;;; ? "/Users/me"
(let ((default-directory "~/.emacs.d/"))
(shell-command-to-string "echo $PWD"))
;;; ? "/Users/me/.emacs.d"
Run Code Online (Sandbox Code Playgroud)
(shell-command) 确实使用缓冲区的default-directory,这意味着没有理由cd访问缓冲区的目录。
我的情况的问题是我错误地git gui在没有关联.git/目录的缓冲区上运行。