问题描述
我正在尝试在 Mac OS X 系统上使用特定的 ruby 版本运行编译命令(耙黄瓜),我目前在终端中使用 rvm 执行此操作.我的 ~/.MacOSX/environment.plist 中有正确的路径,但 emacs 坚持在这条路径前面加上,因此使它无用.我也试过:
I'm trying to get a compile command (rake cucumber) to run with a specific ruby version on my Mac OS X system, I use rvm to do this currently in the terminal. My ~/.MacOSX/environment.plist has the correct path in it, but emacs insists on prepending to this path and therefore making it useless. I've also tried:
(when (equal system-type 'darwin)
(setenv "PATH" (concat "/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin:/Users/fearoffish/.rvm/bin"))
(push "/Users/fearoffish/.rvm/bin" exec-path)
(push "/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin" exec-path)
(push "/Users/fearoffish/.rvm/bin" exec-path))
这是一个 emacs 初学者为了得到我想要的东西而拼命的尝试.它仍然放在它前面,所以我的路径最终是:
It was the desperate attempt of an emacs beginner to get what I wanted. It still prepends in front of it, so my path ends up being:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin
我不希望/usr/bin 和其他人在前面,我希望 my 路径在前面,emacs 路径在最后,我认为这可以解决我的问题.
I don't want /usr/bin and others prepending, I want my path first and the emacs prepended path to be at the end, I reckon this would fix my problem.
我通过简单地打开 Aquamacs 并运行 meta-x compile
然后 echo $PATH
来测试这个.
I test this by simply opening Aquamacs and running meta-x compile
and then echo $PATH
.
有什么想法吗?
推荐答案
sanityinc 对解决方案的一个小修改(在上面的评论中找不到输入它的方法 - 只有我吗?)
A small modification to the solution by sanityinc (couldn't find a way to enter it in the comments above -- is that just me?)
- 我对 shell 使用
-l
选项来强制登录 shell(读取.profile
或.bash_profile
),而不是一个交互式 shell(仅读取.bashrc
). - 我对返回的路径进行了一些字符串修剪(因为检查显示有一个换行符潜入).
- I use
-l
option to the shell to force a login shell (which reads.profile
or.bash_profile
), rather than an interactive shell (which only reads.bashrc
). - I do some string trimming on the returned path (as inspection shows a newline sneaking in).
修改后的代码:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]
]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
这篇关于Emacs 在运行编译命令时忽略我的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!