无法在 tmux 中启动应用程序

Ben*_*eah 11 terminal bash tmux osx-yosemite macos

当我尝试从 tmux 启动 Sublime Text 或 SourceTree 时出现此错误:

$ subl
Unable to launch Sublime Text 2

$ stree
Unable to open SourceTree
Run Code Online (Sandbox Code Playgroud)

似乎我也无法打开 os x 应用程序:

$ open MPlayerX.app
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/MPlayerX.app.
Run Code Online (Sandbox Code Playgroud)

我正在使用 Yosemite OS X 10.10 (14A388a)、带有 zsh、tmux 1.0a 的 iTerm 2。使用 bash 有同样的问题。知道发生了什么吗?

Jon*_*ley 16

更新:在 tmux >= v2.6 时不需要此过程

我发现Brendon Rapp 的一篇文章描述了一个不需要很多别名的解决方案。

$ brew install reattach-to-user-namespace
Run Code Online (Sandbox Code Playgroud)

将以下行添加到 ~/.tmux.conf 的末尾:

if-shell 'test "$(uname)" = "Darwin"' 'source ~/.tmux-osx.conf'
Run Code Online (Sandbox Code Playgroud)

创建一个名为 ~/.tmux-osx.conf 的文件,内容如下:

set-option -g default-command "reattach-to-user-namespace -l bash"
Run Code Online (Sandbox Code Playgroud)
  • 上面的解决方案允许相同的 .tmux.conf 文件在 Linux 和 OS X 下正常工作。如果你只使用 OS X,你可以直接将 'default-command' 选项添加到你的 ~/.tmux.conf 中。

  • 如果您使用 bash 以外的 shell,请在 '-l' 开关后用您的 shell 替换 'bash'。


小智 7

我在 tmux 上遇到了同样的问题,并用reattatch-to-user-namespace和 shell 别名修补了它。

  1. $ brew install reattach-to-user-namespace
  2. $ vi ~/.bash_aliases

    alias subl='reattach-to-user-namespace subl'
    alias stree='reattach-to-user-namespace stree'
    alias open='reattach-to-user-namespace open'
    
    Run Code Online (Sandbox Code Playgroud)
  3. $ source ~/.bash_aliases

不优雅,但有效。

  • 根据文档,只需将此添加到您的`~/.tmux.conf`:`set-option -g default-command "reattach-to-user-namespace -l zsh"` (2认同)