从 finder 打开 gvim/MacVim 时 $PATH 变量未正确设置

发布于 2024-09-11 10:33:40 字数 738 浏览 2 评论 0原文

我正在使用 MacVim(对于 mac 来说基本上是 gvim)。

如果我从命令行打开 macvim,那么我的 $PATH 变量将被正确设置。

如果我通过使用查找器点击打开 macvim,则 $PATH 变量将无法正确设置。

谁能给我一些见解吗?

注意:我知道我的路径至少有一部分是在 ~/.bashrc 中设置的,但我不确定其余部分在哪里设置。


示例:

如果我从终端打开 macvim:

% gvim basic.tex 

然后在 MacVim 中我会:

:!echo $PATH
/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/Applications/MacVim.app/Contents/M
acOS:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/texbin:/usr/X11R6/bin 

这是正确的路径。


当我用鼠标打开文件时(在查找器中)

当我走时:

:!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin  

它给了我一条小路径。为什么?

I am using MacVim (basically gvim for the mac).

If I open macvim from the command line then my $PATH variable will be properly set.

If I open macvim via point and click with the finder, the $PATH variable will NOT be properly set.

Can anyone give me some insight?

Note: I know at least part of my path is set in ~/.bashrc, but I am not sure where the rest of it is set.


Examples:

If I open macvim from the terminal:

% gvim basic.tex 

And then in MacVim I go:

:!echo $PATH
/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/Applications/MacVim.app/Contents/M
acOS:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/texbin:/usr/X11R6/bin 

This is the right path.


When I open the file with the mouse (in finder)

When I go:

:!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin  

It gives me a little path. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无畏 2024-09-18 10:33:40

我也遇到了同样的问题,但它只在将我的默认 shell 设置为 zsh 后才出现,看起来

export SHELL=/bin/zsh

OS X zsh 设置中有一个错误。简而言之,解决方法是将 /etc/zshenv 合并到 /etc/zprofile 中。就我而言,我没有 /etc/zprofile 因此只需移动该文件就可以解决问题:

sudo mv /etc/zshenv /etc/zprofile

这个 post 更详细地描述了该解决方案。

I had this same issue but it only appeared after setting my default shell to zsh like so

export SHELL=/bin/zsh

It seems that there is a bug in the OS X zsh setup. The work around in brief is to merge /etc/zshenv into /etc/zprofile. In my case I didn't have a /etc/zprofile so just moving over the file did the trick:

sudo mv /etc/zshenv /etc/zprofile

This post describes the solution in more detail.

枯寂 2024-09-18 10:33:40

对我来说,只需创建一个从 .zprofile 到 .zshrc 的新符号链接就可以了:

ln -s ~/.zshrc ~/.zprofile

For me, simply creating a new symbolic link from .zprofile to .zshrc did the trick:

ln -s ~/.zshrc ~/.zprofile
回首观望 2024-09-18 10:33:40

设置环境变量的地方
在 Mac 上用于 GUI 应用程序(通过登录窗口启动的应用程序、
Finder 等)是 ~/.MacOSX/environment.plist

或者,在 MacVim 中,您可以选择在登录 shell 中启动 vim 进程(查看首选项)。

有关详细信息,请参阅此内容发布

The place to set environment variables
on the Mac for GUI applications (those started via loginwindow, the
Finder, etc.) is ~/.MacOSX/environment.plist

Alternately in MacVim you can choose to launch vim processes in a login-shell (look in the preferences).

For more info see this post.

陌伤浅笑 2024-09-18 10:33:40

路径的差异可能与登录 shell(登录)和非登录 shell(调出控制台)之间的差异有关。

从 bash 手册页:

当 bash 作为交互式登录 shell 被调用时...它会查找 ~/.bash_profile...

当启动非登录 shell 的交互式 shell 时,bash 会从 /etc/bash.bashrc 和 ~/.bashrc 读取并执行命令...

我为解决此问题所做的是将以下代码添加到我的 ~/.bash_profile 中,告诉它获取我的 ~/.bashrc if它存在:

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

The difference in the PATHs probably has something to do with the difference between a login shell (logging in) and a non-login shell (bringing up a console).

From the bash man page:

When bash is invoked as an interactive login shell ... it looks for ~/.bash_profile...

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc...

What I did to get around this issue was to add the following code to my ~/.bash_profile, telling it to source my ~/.bashrc if it exists:

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文