Sourcetree:Sourcetree 启动的 .sh 脚本不知道 ~/.bash_profile 中的环境变量

Sourcetree: A .sh script launched by Sourcetree dosen't know environment variables from ~/.bash_profile

Sourcetree 允许我们启动一个.sh 脚本,称为自定义操作。我要注册一个 .sh 文件来打开带有 Sublime 文本的文件。在做之前,我做了一个测试,发现有些奇怪。 Sourcetree 启动器的所有者是 hello,Bash shell 的所有者也是 hello,例如:

choegyutaes-MacBook-Pro:MacOS hello$ pwd
/Applications/SourceTree.app/Contents/MacOS
choegyutaes-MacBook-Pro:MacOS hello$ ls -al
total 6752
drwxr-xr-x@  3 hello  admin      102 Feb  4  2015 .
drwxr-xr-x@ 10 hello  admin      340 Aug  9 00:46 ..
-rwxr-xr-x@  1 hello  admin  3456064 Feb  4  2015 SourceTree

但是 Sourcetree 脚本启动器没有从 ~/.bash_profile.

导出的路径
choegyutaes-MacBook-Pro:scripts hello$ cat ~/.bash_profile
#MAVEN
export M2_HOME=/usr/bin/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
#Mysql
export MYSQL=/usr/local/mysql/bin
export PATH=$MYSQL:$PATH
#bash history timestamp
export HISTTIMEFORMAT="%d/%m/%y %T "
#Sublime text
export SUBLIME=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin
export PATH=$SUBLIME:$PATH

我的 shell 脚本 (sublime.sh)

#!/bin/bash
whoami
echo $PATH
sleep 3

来自 Bash shell (iTerm)

的 lanuch 脚本
choegyutaes-MacBook-Pro:scripts hello$ ./sublime.sh
hello
/Applications/Sublime Text.app/Contents/SharedSupport/bin:/usr/local/mysql/bin:/usr/bin/apache-maven-3.3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

从 Sourcetree 启动脚本。

如你所见,echo $PATH 的结果不同,whoami 的结果是一样的。我认为这对 Sourcetree 来说不是问题。这是因为我不熟悉 *nix 系统和环境变量。为什么 Sourcetree 脚本启动器不知道 Sublime 文本的路径?

.bash_profile 仅用于 运行 在终端中设置 bash shell。

您可能正在从快捷方式或菜单中 运行ning SourceTree。

如果您从 bash 提示中 运行 SourceTree,您应该会发现它选择了由 .bash_profile.

设置和导出的环境

假设就是这样,那么您需要您的快捷方式或菜单具有相同的 - 我不知道 OS-X - 但必须有一些为整个用户设置环境的方法上下文(即对于在用户会话下启动的任何进程,菜单中的图形,或 bash shell 或其他任何内容。)