开发者

Why do my TextMate bundles sometimes not have access to environment/shell variables?

I have a TextMat开发者_开发百科e bundle written in ruby that accesses the ENV hash to read shell variables.

It sometimes succeeds in reading this variable, and sometimes doesn't find it. I've been unable to figure out the pattern.

What dictates which shell variables will be visible to a TextMate bundle?

update

ah ha! When I launch TextMate from the command line, it works. If I launch it from the dock, it does not work (even if I then subsequently open a directory from the command line).

So the question now is, why does TextMate choose to pick up different environments in these cases, and is there a way to make them identical?


Textmate is launched via launchd, not from the shell.

Your $PATH will travel over if you run something directly from the shell (open -a Textmate does not work, open will not pass your environment to Textmate).

The ways to get around this are environment.plist, launchctl, or launchd.conf:

Setting environment variables in OS X?

update

If you edit /etc/launchd.conf and reboot, the changes will take effect. Each line can be a launchctl command like setenv VAR_NAME "VAR_VALUE". You could then run this file with launchctl your_file.

It's a pain having to reboot though. And if you want per-user environment settings, this is no good. Apple proposes ~/.launchd.conf could be used for user-specific settings, but has yet to implement this feature.

You could set a script to run on login with a LoginHook and LogoffHook (see Apple's documentation). Or, using LaunchAgents. For detailed directions on how to set up a LaunchAgent, look at nicksay's post on this Macworld post.

The launchctl setenv command doesn't seem to work while logged in. I'm currently banging my head against this.

I ran into basically the same problem you're having today (the Makefile bundle would not pass LIBRARY_PATH to gcc), and now I'm writing a python script that will read a file of variable assignments on login, store a copy of the current environment and that file with the assignments, and then unload all the variables on logout. That also reminds me, I should have an update option. I'll post a comment with the link to a github repo for it here when I'm done. If it works, that is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜