如何在 Mac OS X 上打开 Emacs,使其加载我的 $PATH?
我正在运行 Snow Leopard,并尝试运行 Emacs ,这样当我启动它时,的输出(getenv "PATH")
与 echo $PATH
的 Terminal.app
中的输出相同。
换句话说,我想从 /Applications/Emacs.app
启动 Emacs,并以我的 $PATH
开始。我一直无法弄清楚如何在 emacs 中执行此操作,或者如何启动 emacs。所以我花了大部分精力试图想出一个 shell 脚本,我可以用 Platypus 或 Appify。
所以我现在拥有的最接近的东西是:
echo MYPASSWD | sudo -S -u USERNAME -i nohup /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
它失败了,因为尽管有 -i
标志, nohup 似乎还是丢弃了我的 $PATH 。以下内容不会丢弃我的PATH
,而是打开一个多余的Terminal.app
:
echo MYPASSWD | sudo -S -u USERNAME -i open /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
我尝试通过AppleScript中的do shell script
运行它,也无济于事。
我错过了一些基本的东西吗?看起来这应该不难。谢谢!
I'm running Snow Leopard, and trying to run Emacs such that when I start it up, the output of (getenv "PATH")
is the same as the output in Terminal.app
of echo $PATH
.
In other words, I want to start up Emacs from /Applications/Emacs.app
and have it start with my $PATH
. I haven't been able to figure out how to do this within emacs, or with how I start emacs up. So I've spent most of my effort trying to come up with a shell script that I can wrap with something like Platypus or Appify.
So the closest thing I have right now is:
echo MYPASSWD | sudo -S -u USERNAME -i nohup /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
which fails because it seems that nohup throws away my $PATH, despite the -i
flag. The following does not throw away my PATH
but open a superfluous Terminal.app
:
echo MYPASSWD | sudo -S -u USERNAME -i open /Applications/Emacs.app/Contents/MacOS/Emacs > /dev/null &
I've tried running this through do shell script
in an AppleScript, also to no avail.
Am I missing something basic? It doesn't seem like this should be hard. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
前一段时间我写了一个 elisp 来解析 env 的输出并将其应用到 Emacs 环境中,因为我不想维护 plist。代码位于 http://paste.lisp.org/display/111574。
I wrote a little elisp a while ago to parse the output of env and apply it to the Emacs environment because I didn't want to maintain a plist. The code's at http://paste.lisp.org/display/111574.
GUI 应用程序不是由传统 shell 启动的,也不会从
.profile
、.bash_profile
等常用位置继承环境变量。http://developer .apple.com/library/mac/#documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html%23//apple_ref/doc/uid/20002093-BCIJIJBH 解释了
~/.MacOSX/ environment.plist
是您可能想要添加您最喜欢的 $PATH 等效项的位置。GUI applications are not launched by a traditional shell and do not inherit environment variables from the usual places like
.profile
,.bash_profile
, etc.http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html%23//apple_ref/doc/uid/20002093-BCIJIJBH explains that
~/.MacOSX/environment.plist
is the place you probably want to add your favorite equivalent of $PATH.我遇到了同样的问题,以下是我的解决方法。我创建了 ~/.bashrc 并填充了以下内容:
I ran into the same problem and here's how I worked around it. I created ~/.bashrc and populated it with:
您必须将 PATH 导出到 .app 的位置,因此它会类似于这样:
export PATH=$PATH:/path/to/the/program
这应该允许您只需键入 EMACS,它就会启动。
You have to export the PATH to the location of the .app so it would be something like this
export PATH=$PATH:/path/to/the/program
That should allow you to just type EMACS and it will start up.